5
# $Id: leak.t,v 1.3 2002/03/07 23:04:54 eserte Exp $
9
# Some leak tests. You need Devel::Leak installed and a debugging perl.
10
# I usually use this arguments to perl's Configure:
12
# -Doptimize='-g -DPERL_DEBUGGING_MSTATS' -Dusemymalloc='y'
14
# With the patches for tkGlue.c and pTkCallback.c (see the patches
15
# subdirectory), the problems here should get away.
28
die if $Config{optimize} !~ /-DPERL_DEBUGGING_MSTATS/;
31
print "# tests only work with installed Test and Devel::Leak modules\n";
32
print "# also -DPERL_DEBUGGING_MSTATS have to be set\n";
40
# gather all todos marked with "TODO: number"
42
open(DATA, $0) or die $!;
44
push @todos, $1 if (/^\#\s+TODO:\s+(\d+)/);
47
plan tests => 8, todo => [@todos];
50
my $mw = new MainWindow;
54
# Tests for leaking subroutine set
56
# first binding always creates some SVs
57
$mw->bind("<Motion>" => [sub { warn }]);
59
$c1 = Devel::Leak::NoteSV($handle);
61
$mw->bind("<Motion>" => [sub { warn }]);
63
$c2 = Devel::Leak::NoteSV($handle);
67
$c1 = Devel::Leak::NoteSV($handle);
69
$mw->bind("<Motion>" => sub { warn });
71
$c2 = Devel::Leak::NoteSV($handle);
75
$c1 = Devel::Leak::NoteSV($handle);
77
$mw->bind("<Motion>" => \&test);
79
$c2 = Devel::Leak::NoteSV($handle);
82
my $btn = $mw->Button(-command => sub { warn });
84
$c1 = Devel::Leak::NoteSV($handle);
86
$btn->configure(-command => sub { warn });
88
$c2 = Devel::Leak::NoteSV($handle);
91
# Tests for leaking Tk_GetUid (e.g. canvas items)
93
my $c = $mw->Canvas->pack;
94
$c->createLine(10,10,100,100, -tags => "a");
96
$c1 = Devel::Leak::NoteSV($handle);
98
$c->createLine(10,10,100,100,-tags => "a");
101
$c2 = Devel::Leak::NoteSV($handle);
105
$c1 = Devel::Leak::NoteSV($handle);
107
my $id = $c->createLine(10,10,100,100);
110
$c2 = Devel::Leak::NoteSV($handle);
113
# Tests for leaking widget destroys
114
my $btn2 = $mw->Button;
118
$c1 = Devel::Leak::NoteSV($handle);
120
my $btn2 = $mw->Button;
123
$c2 = Devel::Leak::NoteSV($handle);
126
# Tests for leaking fileevent callbacks
127
$mw->fileevent(\*STDOUT, 'readable', sub { });
128
$mw->fileevent(\*STDOUT, 'readable','');
131
$c1 = Devel::Leak::NoteSV($handle);
132
$mw->fileevent(\*STDOUT, 'readable', sub { });
133
$mw->fileevent(\*STDOUT, 'readable','');
134
$c2 = Devel::Leak::CheckSV($handle);