Jump to content

Memroy allocated to object keeps increasing


You are about to reply to a thread that has been inactive for 98 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I have a set of jewellery that has a script in every colourable part. As there's rather a lot of colourable parts, it's one of the best things to take off when I get somewhere with a script monitor.

So I thought I'd try learning scripting and write a single script that did this.

I've noticed however that every time I do something with the script, my memory usage (according to a script monitor I was given) goes up. And it never seems to go back down again, even if I remove the script from the object.

I guess I'm doing something horribly wrong, but I'd really like this to reduce my resource requirements, not increase them! Any suggestions?

Link to comment
Share on other sites

Posted (edited)

the script currently isn't currently doing anything beyond a listen. i'm making it loop over the prims in the jewellery to try and find the ones it should be updating when it detects a message on channel 2

Every time I save a change to the script, the memory usage goes up (even if i've removed stuff from it). It is a mono script.

I have even removed the script entirely and reset scripts and the memory usage hasn't gone down.

Edited by Hilary Querrien
Link to comment
Share on other sites

You should be able to write a fairly simple script for the root prim that addresses all child prims (or a specific subset that you are interested in).  If your script is taking more memory all the time, you may be saving information unnecessarily in a loop somewhere.  The fact that it doesn't go down when you remove the script, though, suggests that you aren't removing whatever script is causing the problem.  It's probably something leftover that you overlooked.

  • Like 1
Link to comment
Share on other sites

Posted (edited)

what could I be leaving over? or could it be the other scripts i'm trying to get rid of that are the problem? is there some way I can find this out? (before actually removing them because the jewellery while modifiable is no copy) - I thought resetting the scripts would remove any used memory. I just did a save and the memory showed in the usage hud went from 2.25 to 2.31 Mb (and I'm standing here naked apart from the necklace)

Edited by Hilary Querrien
Link to comment
Share on other sites

 

2 minutes ago, Hilary Querrien said:

or could it be the other scripts i'm trying to get rid of that are the problem? is there some way I can find this out? (before actually removing them because the jewellery while modifiable is no copy) - I thought resetting the scripts would remove any used memory.

Yes, exactly.  Get rid of all those scripts in child prims.  You won't need them.  However, I understand why you are reluctant to do that if the jewelry is no-copy.  I suggest doing any scripting (and testing) in a dummy mockup instead of experimenting on the real thing.  If you finally get a script to work, then strip the real jewelry down and put your tested, perfect script in it.

Your script will be fairly simple, but making it work properly will almost certainly mean naming each of the child prims that you want to be able to have changing colors.  You will also need to decide how you want to tell the script to change them (a chat message?  a set of dialog button options? ??)  As Xiija says, SLPPF will make quick work of the job once you have made those preparatory decisions.

Link to comment
Share on other sites

Posted (edited)

if you do a ... reset scripts .. it should show you the names of all the scripts in your item...

then you can check them all for the leak mebbe?

 

I've had times where i copy pasted and the blank or bad spaces i copied  caused my script to bork..

hadda redo it from scratch, not just copy it to a new prim :(

You could also try ... Stop Scripts .. and just turn your own script on and see if it still happens?

Edited by Xiija
Link to comment
Share on other sites

Posted (edited)

sounds like your checker script is doin something weird then?

mebbe try adding your own memory checker inside your script?

kinda like ...

 integer mem = llGetUsedMemory( );
 llOwnerSay("MEM: " + (string)mem );

 

Edited by Xiija
Link to comment
Share on other sites

That monitor may be telling you something other than you expect.  From what you've said, it sounds like you are concerned about memory use, but that may not be the best thing to monitor.  You can get one measure of how much memory your avatar's script are allocated by using Avatar >>> Attachment Scripts  (that's Avatar >> Avatar Health >> Scripts if you are in Firestorm).  It looks like this:

b51506652614cee99d3436da143c11c9.png

That will tell you how much memory is allocated for each script on your avatar, but that's not particularly useful.  For one thing, the amount of memory you are allocated only tells you the maximum that those scripts might actually use. For another thing, the memory that your scripts use is likely to be a tiny fraction of the region's capacity.  And most of those scripts aren't actually doing anything most of the time. They are just sitting there.

A better thing to monitor might be the amount of script time all of those scripts are using.  One way to do that is to go to a totally empty region somewhere (Like the Nuclear Fishing region) and open your Statistics Bar (CTRL + Shift + 1).  Scroll down the display to see how much Script Time is being used at the moment.  It will bounce around a little, but should be pretty stable.  When I do that, I see that all scripts in the region are using 0.197 milliseconds of time in each frame (1/45 of a second).  Now take off every single thing that contains a script (all those those things listed in the display I just posted above) and see what the Script Time is.  When I do that, it drops to 0.025 milliseconds ( Probably a couple of Linden Lab utility scripts running somewhere. ).   So, all the scripted things on my avatar were keeping the region's servers busy for 0.197 - 0.025 = 0.072 milliseconds during a frame. Compared to the total  (1/45 = 22.2 milliseconds), that means the servers are spending about 0.3% of their time keeping my scripts running.  That's really tiny.  Unless your avatar is using a whale of a lot more server time than mine is, it's not going to make much difference whether you take off a couple of pieces of jewelry.  The time to worry is when you are demanding three or four times that much of the server's attention. (Forty people in a busy region, each using 1% or more of the server time, could create a real problem -- big time lag. )  So, watch script time rather than script memory if you are concerned about how much you contribute to local server load.  Reducing the number of scripts in your jewelry is a very good idea, but not primarily because of memory.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

5 hours ago, Hilary Querrien said:

I've noticed however that every time I do something with the script, my memory usage (according to a script monitor I was given) goes up. And it never seems to go back down again, even if I remove the script from the object.

What is this "script monitor" you were given? How much memory is it reporting exactly? Based on what you've said, it either doesn't work correctly (since it doesn't change memory usage when you remove the script being monitored) or you are misinterpreting the information it's giving you (which is fairly easy to do).

To complement Rolig's explanation, a shorter explanation would be:

  • Scripts can only see the maximum memory limit of other scripts, but not the amount of memory they are currently using.
    • Scripts can accurately see their own memory usage.
  • Script time is considered more useful, and the 30-minute average can be seen by all scripts.
  • Like 1
Link to comment
Share on other sites

Something I've seen, using both the viewer Avatar Health/Scripts window and llGetObjectDetails, is that the script memory apparently gets counted multiple times when you edit the script in an object.

Try this routine:

  • Change into a scriptless outfit. Rez a prim. Wear it. Check Avatar Health/Scripts. It will show 0 kb memory used.
  • Add a new script to the object. Refresh avatar scripts. It will show 64 kb memory used.
  • Edit the script (I add a space at the end and then delete that space so the script remains the same). Save the script. Refresh avatar scripts. It now shows 128 kb total, but only 64 kb for the object.
  • Repeat the above. Now it's 192 kb total, but 64 for the object.
  • TP to another region.
  • Refresh avatar scripts. The total and the object now both show 64 kb.
  • Edit the script again...

It's a bug, I guess, but not one that's annoyed me enough to file a JIRA.

  • Like 1
  • Thanks 5
Link to comment
Share on other sites

I rarely ever edit a script in situ.  Generally I'll do my edits in inventory and when I've saved and am ready to test the logic, I'll delete the existing script from the in world object (or attachment) and add in the newly edited script.  This way keeps me sane in that what's in personal inventory is always the most up to date version and I don't second guess myself about if the object has a newer edit. 

So it's got me wondering, KT, if that behavior you describe would also be evident in how I do my editing.  I might need to experiment some and find out.

Link to comment
Share on other sites

Memory in use in scripts is reported before garbage collection.  Until you run out and force a garbage collection, the heap just increases.

If you really need an accurate memory usage, you can do this:
 

integer memlimit = llGetMemoryLimit(); // how much are we allowed?
llSetMemoryLimit(memlimit-1); // reduce by 1 to force GC
llSetMemoryLimit(memlimit); // set it back
integer freemem = llGetFreeMemory(); // get free memory left after GC, hopefully larger.

Don't do this too often.

I do this when free memory seems to be getting too small, to see if the problem is real or whether it's just time for a garbage collections. My NPCs do this to decide whether they can continue allocating memory or need to take some corrective action to conserve memory.

  • Like 1
  • Thanks 2
Link to comment
Share on other sites

22 hours ago, Anna Salyx said:

I rarely ever edit a script in situ.  Generally I'll do my edits in inventory and when I've saved and am ready to test the logic, I'll delete the existing script from the in world object (or attachment) and add in the newly edited script.  This way keeps me sane in that what's in personal inventory is always the most up to date version and I don't second guess myself about if the object has a newer edit. 

So it's got me wondering, KT, if that behavior you describe would also be evident in how I do my editing.  I might need to experiment some and find out.

Deleting the script and putting in the new one doesn't actually reduce the memory usage - I checked that when I was trying desperately to get my memory back. Though I imagine you'd have less of an issue as you wouldn't be updating the script in the object so often.

Link to comment
Share on other sites

Typical that I'd counsel laziness, but I'd advise getting something working first and only then start thinking about memory use. It's certainly true that good "memory hygiene" is a consideration in design and early implementation but it's unlikely to be worth measuring until there's something working, even (especially?) if it has to be tested at reduced scale to stay within hard memory limits.

In this case, it seems some potentially productive development time may have been lost to faulty memory measurement tools. My advice is to simply ignore them. Only once everything is working (or the script is literally throwing stack/heap collisions), start monitoring inside the script itself with llGetUsedMemory(), as @Xiija suggests above. That's when it's important to look for memory leaks.

Also, don't be reluctant to post a rough, early, bug-ridden version of the program you're working on; we may be able to save you some time and aggravation. Just use the "<>" button to get a format-friendly place to paste the code.

Link to comment
Share on other sites

It really does seem that you have been tripping over the bug that Rider Linden highlighted in his post yesterday.  You may also be tracking memory use with a flawed monitoring script, but my money is on the bug.  Unless you are actually seeing some loss of performance, I'd be inclined to note it as an annoying curiosity and then move on.

  • Like 1
  • Haha 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 98 days.

Please take a moment to consider if this thread is worth bumping.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...