Jump to content

Clear Memory Question


Clayn Sharkfin
 Share

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

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

Recommended Posts

From the wiki article on llGetFreeMemory:  

Quote

In Mono the value returned is the amount of free memory available to the script prior to garbage collection being run. This means that memory that is awaiting garbage collection counts against the scripts 64KiB allotment.

The only way I know to clear the memory yourself, without waiting for the garbage collector, is to reset the script, though there may be other ways of hurrying things along (a state change, maybe?  Just a guess).

Link to comment
Share on other sites

On 23/09/2017 at 3:45 PM, Clayn Sharkfin said:

Can anyone tell me if there is any possible way to clear Memory in Mono?

There is no need to reset the script ; you have only to exit the current event where your script is running ( for instante , to exit out of the ' 'touch_end '  event , or thr 'inkl_message_event'  or the 'on_rez" event etc ..

The garbage colletor is called when you exit your running event.

If your event is running a function ,  when your script exit the function but continues to work in the same event  , it  doesn t call the garbage collector .

If your event is running a loop,  when your script exit the loop  but continues to work in the same event  , it  doesn t call the garbage collector .

 

Edited by Miranda Umino
Link to comment
Share on other sites

I am not so sure about that,  @Miranda Umino.    I have just used this test script, compiled in mono:

default
{
    state_entry()
    {
       llOwnerSay("In state entry, llGetFreeMemory returns "+(string)llGetFreeMemory());
    }

    touch_start(integer total_number)
    {
        llOwnerSay("at the start of the touch_start event, llGetFreeMemory returns "+(string)llGetFreeMemory());
        integer counter;
        integer max = 100;
        list temp;
        do{
            temp +=[llGetKey()];
        }
        while (++counter < max);
        llOwnerSay("llGetFreeMemory is now "+(string)llGetFreeMemory());
        llMessageLinked(LINK_THIS,0,"","");
    }
    
    link_message(integer sender, integer number, string str, key id){
        
        llOwnerSay("In the Link Message event, llGetFreeMemory returns "+(string)llGetFreeMemory());
        llSetTimerEvent(30.0);
    }
    
    timer(){
        llSetTimerEvent(0.0);
        llOwnerSay("And in the timer event, 30 seconds later, llGetFreememory returns "+(string)llGetFreeMemory()); 
        llResetScript();  
    }
}

Here's what the object said:

[13:18] Object: In state entry, llGetFreeMemory returns 59100
[13:18] Object: at the start of the touch_start event, llGetFreeMemory returns 59100
[13:18] Object: llGetFreeMemory is now 48858
[13:18] Object: In the Link Message event, llGetFreeMemory returns 48858
[13:18] Object: And in the timer event, 30 seconds later, llGetFreememory returns 48858
[13:18] Object: In state entry, llGetFreeMemory returns 59100

So it looks to me as if llGetFreeMemory -- which according to the Wiki is, in Mono Scripts,  "the amount of free memory available to the script prior to garbage collection being run. This means that memory that is awaiting garbage collection counts against the scripts 64KiB allotment" -- doesn't reduce even after exiting two events, and the garbage collector clearly cannot be relied upon to clear the memory in a timely manner.

  • Like 2
Link to comment
Share on other sites

2 hours ago, Innula Zenovka said:

integer max = 100; list temp; do{ temp +=[llGetKey()]; } while (++counter < max);

To be picky, you really should use llGenerateKey() and not like elements(in this case, the same key added each time) when testing memory consumption of lists in Mono.

I'm sure some computer science grad/enthusiast can explain how Mono handles like elements present in any given memory block to lower the memory footprint.

Link to comment
Share on other sites

Using llGenerateKey() uses slightly less memory, it seems:

In state entry, llGetFreeMemory returns 59100
[18:10] Object: at the start of the touch_start event, llGetFreeMemory returns 59100
[18:10] Object: llGetFreeMemory is now 49368
[18:10] Object: In the Link Message event, llGetFreeMemory returns 49368
[18:11] Object: And in the timer event, 30 seconds later, llGetFreememory returns 49368
[18:11] Object: In state entry, llGetFreeMemory returns 59100

  • Like 2
Link to comment
Share on other sites

@Miranda Umino you confuse the handling of the stack pointer with a garbage collection.

If an event or user defined function is entered - the stack pointer is memorized then all parameters and runtime stuff is put on the stack, the event or function is started which puts all the local variables on the stack. When the event or function ends the stack pointer is set back to the memorized value and so the memory that was occupied is free.

That has nothing to do with a garbage collection.

A garbage collection causes very high cpu load and I assume that it's triggered never or only on things like a sim restart for example. If you have a lazy garbage collection that only triggers when the script is out of memory you will need do to it never for many of the scripts and rarely for rest. In this case you need less cpu power and a bit more memory.

LL will surely have a statistics and have found an optimum here. Depends on costs - what is cheaper? Saving cpu power or saving memory.

Imagine that there are many 1000 scripts on a sim and there are many sims hosted on one server.

Edited by Nova Convair
Link to comment
Share on other sites

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

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...