Clayn Sharkfin Posted September 23, 2017 Share Posted September 23, 2017 Can anyone tell me if there is any possible way to clear Memory in Mono? Link to comment Share on other sites More sharing options...
Innula Zenovka Posted September 23, 2017 Share Posted September 23, 2017 Reset the script? Clear variables, especially lists, when you're finished with them ( lMyList = [])? Link to comment Share on other sites More sharing options...
Clayn Sharkfin Posted September 23, 2017 Author Share Posted September 23, 2017 Clearing Variables does nothing at all to the memory, the llGetFreeMemory() shows no change and once that shows no more memory the script fails. Link to comment Share on other sites More sharing options...
Innula Zenovka Posted September 23, 2017 Share Posted September 23, 2017 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 More sharing options...
Clayn Sharkfin Posted September 23, 2017 Author Share Posted September 23, 2017 I did read somewhere about state change and that it would clear it, however when i tried it that didn't seem to do anything. Link to comment Share on other sites More sharing options...
Innula Zenovka Posted September 23, 2017 Share Posted September 23, 2017 Maybe ask over the street at SLU? Void Singer posts there a lot and she knows more about script memory than most of us. Link to comment Share on other sites More sharing options...
Nova Convair Posted September 23, 2017 Share Posted September 23, 2017 The memory is freed after a garbage collection and that is handled automatic. A garbage collection is forced when you exceed the max. memory. Besides of that it's out of your influence. So if you want to force it you need to reset the script. Link to comment Share on other sites More sharing options...
Miranda Umino Posted September 27, 2017 Share Posted September 27, 2017 (edited) 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 September 27, 2017 by Miranda Umino Link to comment Share on other sites More sharing options...
Innula Zenovka Posted September 27, 2017 Share Posted September 27, 2017 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. 2 Link to comment Share on other sites More sharing options...
Lucia Nightfire Posted September 27, 2017 Share Posted September 27, 2017 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 More sharing options...
Innula Zenovka Posted September 28, 2017 Share Posted September 28, 2017 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 2 Link to comment Share on other sites More sharing options...
Lucia Nightfire Posted September 28, 2017 Share Posted September 28, 2017 Curious. I do use the memory defrag method of list appending in most Mono apps so I could be confusing behaviors too. Link to comment Share on other sites More sharing options...
Nova Convair Posted September 28, 2017 Share Posted September 28, 2017 (edited) @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 September 28, 2017 by Nova Convair Link to comment Share on other sites More sharing options...
Recommended Posts
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