CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Perl/Tk memory leak?

 



thodi
stranger

Nov 7, 2001, 11:12 PM

Post #1 of 3 (313 views)
Perl/Tk memory leak? Can't Post

When I create a Tk::Dialog window (or other Tk::Toplevel widgets), destroy (and even undef) it, there is still a refenrence to it somewhere. The following code reproduces this:

Code
#!/usr/bin/perl -w 
use Devel::Peek;
use Tk;
use Tk::Dialog;

my $mw = MainWindow->new();
my $d = $mw->Dialog();
$d->destroy();
undef %$d;
print STDERR "Dialog:\n";
Dump $d;
__END__

perl -v is "v5.6.0 built for 9000/777-hpux", $Tk::VERSION is "800.023".
Any hints?



Coderifous
journeyman

Nov 8, 2001, 9:49 PM

Post #2 of 3 (303 views)
Re: Perl/Tk memory leak? [In reply to] Can't Post

Perl has a built-in Garbage Collector that automatically handles all the freeing up of memory. So you shouldn't have a memory leak. I read this in the "perldoc perltoot" document on Object Oriented programming and that's when I learned of Perl's reserved DESTROY method for classes. I'm pretty new to OO Perl, but from what I understand, the memory leak should not be a worry of the Perl Programmer. Due to my freshness, I would not be surprised if I were corrected by someone more experienced.... oh... say... Marcus maybe...Wink

--Jim

PS - mainloop() ?



mhx
Enthusiast / Moderator

Nov 8, 2001, 10:16 PM

Post #3 of 3 (302 views)
Re: Perl/Tk memory leak? [In reply to] Can't Post

Thanks for your effort, Jim, but we know about the garbage collector. (I say 'we' because thodi is sitting no more than 10 meters away from me. Wink
I'm having several ideas on what the problem could be, but they all need to be verified.

The snippet thodi posted was only an example to demonstrate the problem. Actually, the problem occurs in a large Tk project where some hundred windows are opened and closed all the time. If the application runs for a long time, the system runs out of memory. And the problem seems to be that either someone holds an extra reference to the Tk widget or the reference counter is not properly decremented or set at the time the widget is created. Thus, the garbage collector cannot clean up the waste.

So if someone has experienced similar problems, please post any suggestions on what the problem could be.

-- Marcus


Code
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= 
($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives