Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

coding error or memory leak?

Adam Marker
new scripter
Join date: 2 Jan 2004
Posts: 104
08-04-2004 13:54
I am working through a collection of keys, and am trying to count contiguous sequences of duplicate keys.

When I execute the script below, I lose about 50 bytes of free memory each time through the outer loop. If I comment out the inner loop (lines in blue), no leak.

This is as simple as I could get the example and still have it leak. Does it look like there is anything wrong with the code, or is SL just leaking? Sample output at the bottom.

Thanks for any ideas (including any workarounds)!

CODE
default {

state_entry() {
key ownerKey ;
key prevOwnerKey ;
integer count = 0 ;

while (count < 8) {
ownerKey = "a12e2fe7-ffe3-0827-6e34-012eac7d6ce9" ;
prevOwnerKey = ownerKey ;

while (ownerKey == prevOwnerKey) {
prevOwnerKey = ownerKey ;

count++ ;

// artificially change owner every time
if (count % 2 == 0)
ownerKey = "deba040f-23da-adf4-45c7-df681aa1d39b" ;
else
ownerKey = "95d0d24c-deae-2e62-d084-a3c9dd6643a3" ;
} // while same owner


llWhisper(0, (string) count + " free=" + (string) llGetFreeMemory()) ;
} // while more labels

} // state_entry

} // default


leaky object whispers: 1 free=15746
leaky object whispers: 2 free=15702
leaky object whispers: 3 free=15658
leaky object whispers: 4 free=15614
leaky object whispers: 5 free=15570
leaky object whispers: 6 free=15526
leaky object whispers: 7 free=15482
leaky object whispers: 8 free=15438
Adam Marker
new scripter
Join date: 2 Jan 2004
Posts: 104
alternative workarounds welcome
08-04-2004 15:16
To summarize my intent -- I am trying to abbreviate a long list of keys using "run length encoding".

The input might be something like:
key1
key1
key1
key2
key3
key4
key4

The output would use the format [# of repetitions, key]:
3,key1
1,key2
1,key3
2,key4
Adam Marker
new scripter
Join date: 2 Jan 2004
Posts: 104
while (leak) { }
08-04-2004 20:04
Someone sent me another example (thanks!) -- and helped me to think of some things to try.

I changed the inner while so the condition is not evaluated directly. No more leak. Looks like a bug to me; I will report it.

CODE

integer sameKey = TRUE ;

while (sameKey) {
prevOwnerKey = ownerKey ;
ownerKey = ...
sameKey = (ownerKey == prevOwnerKey) ;
} // while same owner
Grim Lupis
Dark Wolf
Join date: 11 Jul 2003
Posts: 762
08-06-2004 06:32
I'm glad you figured out what was actually causing it, Adam. I was doing some testing last night and thought some things were really getting screwed up!
_____________________
Grim

"God only made a few perfect heads, the rest of them he put hair on." -- Unknown
Adam Marker
new scripter
Join date: 2 Jan 2004
Posts: 104
and... joke's on me!
08-06-2004 08:18
Thanks Grim. The bug has been acknowledged, and will get fixed if a future release.

My original design kept all data in the script. When I started running out of memory, it seemed logical to blame my giant lists of stuff. So I changed to an XML-RPC implementation, where I kept no data in the script. I ran out of memory even faster! I find that really funny (I like irony). And I learned to use XML-RPC. Not a loss.
Grim Lupis
Dark Wolf
Join date: 11 Jul 2003
Posts: 762
Re: and... joke's on me!
08-06-2004 08:40
From: someone
Originally posted by Adam Marker
My original design kept all data in the script. When I started running out of memory, it seemed logical to blame my giant lists of stuff.


I had similar problems last year with some scripts, during the error of the List2Leak and String2Leak bugs. I of course got flustered and pissed at how little data I could actually store in a list.

This was before RPC even existed. So I just gave up on it. :-/
_____________________
Grim

"God only made a few perfect heads, the rest of them he put hair on." -- Unknown