Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Memory Leak?

Iron Perth
Registered User
Join date: 9 Mar 2005
Posts: 802
01-22-2006 13:39
CODE

default
{
state_entry()
{
list mb=[NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY];
mb=mb+mb+mb+mb+mb+mb+mb+mb+mb+mb+mb+mb;
list eatupMemory1=[NULL_KEY,""];

integer i=0;
list mtest;
integer j=0;
for(i=0;i<8;i++) {
for(j=0;j<10;j++) {
mtest=mtest+[1,NULL_KEY, <1,1,1>, <1,1,1,1>, "asdf"];
}
mtest=[];
llOwnerSay((string)llGetFreeMemory());
}

}
}



output:

CODE

Object: 44
Object: 44
Object: 44
Object: 44
Object: 44
Object: Script run-time error
Object: Stack-Heap Collision


Since the memory gets released on each iteration, I'm unclear as to why there would be a stack heap collision. Other versions of this show a decline in free memory, however since free memory is buggy, I didn't quote those.
Introvert Petunia
over 2 billion posts
Join date: 11 Sep 2004
Posts: 2,065
01-22-2006 14:25
From: Iron Perth
Since the memory gets released on each iteration, I'm unclear as to why there would be a stack heap collision.
Because the LSL VM is indeed buggy; so much so that it appears any work on the LL VM has stopped long ago in favor of the Mono VM replacement which is well underway but (to my knowledge) has no expected release date associated with it.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
01-22-2006 23:47
i've always wondered exactly how it allocated the data into the memory space. It probably isn't a leak but a bug in the (de)allocation routines with regards to fragmentation. 16k of memory is so little the memory has to be handled intellegently. LL's design decision to only allow 16k of memory and not allow for pointers or a lower level LSL language was a lapse in judgement that we usualy expect Apple to make (no offense Apple).

The big advantage of Mono: script memory is allocated dynamicly, meaning 90% of scripts will use significantly less then 16k of memory. Sims *should* run faster because of this alone.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
01-23-2006 07:25
Yeh, if they were going to cram programs into 16k they should have based LSL on Forth.

CODE
variable handler
state default
: state_entry ( --- )
0 handler ! "Bashi-bazouk" 1. 1. 1. <> 1. llSetText ;
: on_rez ( param --- )
dup 0= if drop llResetScript else "" NULL_KEY "" llSetListenEvent handler ! then ;
Introvert Petunia
over 2 billion posts
Join date: 11 Sep 2004
Posts: 2,065
01-23-2006 07:42
From: Argent Stonecutter
Yeh, if they were going to cram programs into 16k they should have based LSL on Forth.
INTERCAL!
Blueman Steele
Registered User
Join date: 28 Dec 2004
Posts: 1,038
recompile?
01-23-2006 10:34
hmmm does that mean recompiling every script in a sim might fight lag?
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
01-23-2006 10:41
I *think* the VM, and perhaps also the compiler, don't handle scope very well, especially at the code block level. For instance, I wonder if this would work correctly if you put everything inside the for(i) in a separate function, and called that function from the (i) loop. In that case the memory would get allocated in a different function, and when that returns, it might clean it up better. Just a guess.
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
01-23-2006 12:21
Intercal? For shame! Forth is a beautiful, lyrical language with an elegant structure and tremendous flexibility and versatility. Just because it doesn't look like "C" doesn't mean it should be compared with a joke language.
Fenrir Reitveld
Crazy? Don't mind if I do
Join date: 20 Apr 2005
Posts: 459
01-23-2006 13:02
Sorry, I got to back Argent on this one. I would love to see a "lightweight" LSL along the lines of Forth. But then again I am biased, as I've been using Forth on-and-off both professionally (Sun' s OpenBoot) and personally (MUF on MUCKs) for a while now.

INTERCAL? Before my time, so no comment. ;)

It would be nice if we could at least work with the VM directly by writing virt opcodes ourselves.

Don't get me wrong, not bashing the Linden's ability to write scripting engines. LSL is a compromise between Easy of Use and Small Tight Language. It's just...not very good at either. :)

*goes back to retrying to remember it's llStringLength and llGetListLength, or that it's llDeleteSubList and llListInsertList...*
Introvert Petunia
over 2 billion posts
Join date: 11 Sep 2004
Posts: 2,065
01-23-2006 13:15
From: someone
Intercal? For shame! Forth is a beautiful, lyrical language with an elegant structure and tremendous flexibility and versatility. Just because it doesn't look like "C" doesn't mean it should be compared with a joke language.
My sincere apologies, no offense to forth intended; it used to be my favorite Sun boot-time driver hook language (and, coincidentally, the only one).

INTERCAL just plain amuses me.
Iron Perth
Registered User
Join date: 9 Mar 2005
Posts: 802
01-23-2006 15:38
From: Strife Onizuka
It probably isn't a leak but a bug in the (de)allocation routines with regards to fragmentation.


Call it fragmentation or memory leak - it is still the same problem .. if we use the memory eventually we run out, even if we release everything.

Usually this is not a big problem when you have lots of memory free .. the fragmentation leak is slow enough you can manage it except with periodical resets .. which complicate the user experience too much.

I guess we can't really except a fix for this, however, with mono around the corner.
Iron Perth
Registered User
Join date: 9 Mar 2005
Posts: 802
01-23-2006 16:35
The solution in situations such as these (when there are bugs in underlying memory models) is to write a memory pool and handle all deallocation/allocation ourselves.

Unfortunately, because we can't even allocate our own memory pools, I'm not sure this is possible.

LL, this is a deal breaker. Please fix!
Rickard Roentgen
Renaissance Punk
Join date: 4 Apr 2004
Posts: 1,869
01-23-2006 17:01
This is something that will probably be addressed durring the lsl backend conversion to mono byte code. So I'd say they are working on it.
_____________________
Greg Hauptmann
Registered User
Join date: 30 Oct 2005
Posts: 283
01-23-2006 20:27
as a newbie (well hopefully I'm little beyond this stage now) am I making a mistake ramping up on LSL right now? i.e. I see mention of this "mono" upgrade? Anyone got links to some info on this "mono" upgrade? It isn't the C# version of LSL is it? (I thought someone mentioned this at one stage in a thread)
Rickard Roentgen
Renaissance Punk
Join date: 4 Apr 2004
Posts: 1,869
01-23-2006 21:25
From: Greg Hauptmann
as a newbie (well hopefully I'm little beyond this stage now) am I making a mistake ramping up on LSL right now? i.e. I see mention of this "mono" upgrade? Anyone got links to some info on this "mono" upgrade? It isn't the C# version of LSL is it? (I thought someone mentioned this at one stage in a thread)


Mono is essentially an open source version of the .net framework. I think that a C# program will run on a machine using the mono framework

However, the upgrade to mono does not mean the LSL will change at all, at least not at first.

Mono and .net compilers both compile code into a bytecode, which is more efficient than the what LSL currently compiles into. That's the main part of the upgrade. To a scripter, it will not look much or at all different. It will run much faster and take fewer server resources.

So no, ramping up lsl is not a mistake. In the future, the conversion to mono may allow for more datatypes, more functions, pass by reference, faster timers and possibly even object orientation or the ability to write scripts in a mono/.net language of your choosing, but that will all happen slowly and you'll be ahead of the game if you already understand LSL.

Babbage Linden has posted about the mono conversion on his blog, here
_____________________