For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > May 2005 > Possible memory leak caused by configure(-cursor => ...)









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 Possible memory leak caused by configure(-cursor => ...)
David Thomas

2005-05-01, 9:03 pm

#!/usr/bin/perl -w
#
# This program seems to leak memory when running under Perl 5.8.2
# and Tk 804.025 on i686-linux (compiled with gcc 2.96). It does
# not seem to leak on sun4-solaris. The leak goes away if the
# Listbox is removed, but the Listbox can be replaced with a Text
# widget and the leak still occurs.
#
# I have observed the same problem using $mw->Busy() and $mw->Unbusy(),
# which also use $w->configure(-cursor => ... ).
#
# Is this a known problem? Should I simply upgrade my Tk package?
# Have I overlooked something?
#

use strict;
use Tk;

sub toggle_cursor { my($mw, $countref) = @_;
my $count = ${$countref}++;
if ($count % 2) {
$mw->configure(-cursor => 'left_ptr');
} else {
$mw->configure(-cursor => 'watch');
}
$mw->after(1000, [ \&toggle_cursor, $mw, $countref ]);
}

sub leak3 {
my $count = 0;
my $mw = new MainWindow( -title => "leak3" );
my $buttons = $mw->Frame(-relief => 'groove', -borderwidth => 2);
my $cancel = $buttons->Button(-text => 'Cancel', -width => 6,
-command => sub { $mw->destroy() } )->pack(-side => 'left');
$buttons->pack(-side => 'top', -fill => 'x',
-ipadx => 2, -ipady => 2, -pady => 2);
my $listbox = $mw->Listbox()->pack(-fill => 'both', -expand => 1);
$listbox->insert('end', 'foo');
$listbox->insert('end', 'bar');
$listbox->insert('end', 'baz');

$mw->after(1000, [ \&toggle_cursor, $mw, \$count ]);

Tk::MainLoop();
}

leak3();

__END__

--
David Thomas (dthomas@ti.com)
Texas Instruments, Houston 281-274-2347

-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server. If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to majordomo@lists.stanford.edu

Sponsored Links







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

Copyright 2008 codecomments.com