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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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



Nov 7, 2001, 11:12 PM

Post #1 of 3 (324 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:

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

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

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


Nov 8, 2001, 9:49 PM

Post #2 of 3 (314 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


PS - mainloop() ?

Enthusiast / Moderator

Nov 8, 2001, 10:16 PM

Post #3 of 3 (313 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



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

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