For Programmers: Free Programming Magazines  


Home > Archive > Tcl > March 2004 > Memory Leak Redux: The Answer?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Memory Leak Redux: The Answer?
De Clarke

2004-03-29, 4:37 pm


OK, y'all -- try this:

1) start up a tcl interp with tclX.

2) write a little script or type by hand

keylset data foo {}
set v [keylget data foo]

loop i 1 1000 {

loop j 0 1000 {
set e [lvarpop v]
}

sleep 5

}

and watch it groooooow... by approx 50K per i loop, by my
very rough reckoning.

btw, shouldn't there be some kind of error when you try to lvarpop
off a null list? something like "list is empty, no more elements
to pop"?

there isn't in any of my local tcl versions. so I'm guessing this
has always been legal.

there's a case in my realtime app where the value of an array may
be null. the original code looks kinda like this

set e ""
set err [catch {set e [lvarpop v]} res]
if {$err} {
... do something different ...
}

the error is not thrown, as seen above... and the interp eats a wee
bit more memory with each lvarpop.

what is interesting is that if v is set by

set v {}
set v [list {}]
set v [list]

the memory leak is not seen.

and if element foo of the keyed list is set by

keylset data foo bar

the leak is not seen.

so it looks like there is some kind of deep voodoo about a keyed
list element whose value is NULL, when that value is retrieved
and handed to lvarpop.

workarounds are simple and obvious. I have just applied one to
the app. and sure enough its VSZ has stabilised around 11M, which
is what one would expect based on its array indexing, etc. --
it no longer grows perpetually.

anyway, I invite anyone to try reproducing, or refuting, our
results... and if Jeff is now the keeper of TclX, I hope this
doesn't wreck his w :-)

de

--
..............................................................................
:De Clarke, Software Engineer UCO/Lick Observatory, UCSC:
:Mail: de@ucolick.org | Your planet's immune system is trying to get rid :
:Web: www.ucolick.org | of you. --Kurt Vonnegut :
:1024D/B9C9E76E | F892 5F17 8E0A F095 05CD EE8B D169 EDAA B9C9 E76E:

Jeff Hobbs

2004-03-31, 12:44 pm

De Clarke wrote:

> 1) start up a tcl interp with tclX.
> 2) write a little script or type by hand

...
> and watch it groooooow... by approx 50K per i loop, by my


Confirmed growth with latest TclX.

> btw, shouldn't there be some kind of error when you try to lvarpop
> off a null list? something like "list is empty, no more elements
> to pop"?


That's a design question, and they obviously decided that
popping from something with 0 elements shouldn't fail.

> anyway, I invite anyone to try reproducing, or refuting, our
> results... and if Jeff is now the keeper of TclX, I hope this
> doesn't wreck his w :-)


Hey, just because I make a few commits, doesn't mean you
can't hunt down the mem leak yourself. ;)

--
Jeff Hobbs, The Tcl Guy
http://www.ActiveState.com/, a division of Sophos
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com