#!/usr/bin/perl -- use strict; use warnings; use Wx; use Devel::Leak; use Scalar::Util;; Main( @ARGV ); exit( 0 ); sub Main { my $app = Wx::SimpleApp->new; my $frame = Wx::Frame->new( undef, -1, "", ); $frame->SetBackgroundColour( Wx::wxBLACK() ); $frame->SetSizer( Wx::BoxSizer->new( Wx::wxVERTICAL() ) ); my $text = Wx::TextCtrl->new( $frame, -1, join( ' ', "\n", Perl => $], Wx => $Wx::VERSION, Wx::wxVERSION_STRING, "\n" ), [ -1, -1 ], [ -1, -1 ], Wx::wxTE_MULTILINE() ); my $b1 = Wx::Button->new( $frame , -1, "new f new p", ); my $b2 = Wx::Button->new( $frame , -1, "new f child p", ); my $b3 = Wx::Button->new( $frame , -1, "new f child p destroy", ); my $b4 = Wx::Button->new( $frame , -1, "new f weaken child p destroy", ); my $b5 = Wx::Button->new( $frame , -1, "new f weaken circle child p destroy", ); Wx::Event::EVT_BUTTON( $frame, $b1, sub {my $count1 = Devel::Leak::NoteSV(my $handle); for(1..100){ Wx::Panel->new ; Wx::Frame->new( $frame ,-1,"goner" ); } my $count2 = Devel::Leak::CheckSV($handle); $text->AppendText( join '', "Count1 = '",$count1,"'\n", "Count2 = '",$count2,"'\n", "Diff = '",$count2-$count1,"'\n" ); $text->AppendText( psmem('new f new p') ); } ); Wx::Event::EVT_BUTTON( $frame, $b2, sub {my $count1 = Devel::Leak::NoteSV(my $handle); for(1..100){ Wx::Panel->new( Wx::Frame->new( $frame ,-1,"goner" ) ); } my $count2 = Devel::Leak::CheckSV($handle); $text->AppendText( join '', "Count1 = '",$count1,"'\n", "Count2 = '",$count2,"'\n", "Diff = '",$count2-$count1,"'\n" ); $text->AppendText( psmem('new f child p') ); } ); Wx::Event::EVT_BUTTON( $frame, $b3, sub {my $count1 = Devel::Leak::NoteSV(my $handle); for(1..100){ my $f = Wx::Frame->new( $frame ,-1,"goner" ) ; Wx::Panel->new( $f )->Destroy; $f->Destroy; } my $count2 = Devel::Leak::CheckSV($handle); $text->AppendText( join '', "Count1 = '",$count1,"'\n", "Count2 = '",$count2,"'\n", "Diff = '",$count2-$count1,"'\n" ); $text->AppendText( psmem('new f child p destroy') ); } ); Wx::Event::EVT_BUTTON( $frame, $b4, sub {my $count1 = Devel::Leak::NoteSV(my $handle); for(1..100){ my $f = Wx::Frame->new( ($frame ),-1,"goner" ); my $p = Wx::Panel->new( Scalar::Util::weaken($f) ); $p->Destroy; $f->Destroy; undef $p; undef $f; } my $count2 = Devel::Leak::CheckSV($handle); $text->AppendText( join '', "Count1 = '",$count1,"'\n", "Count2 = '",$count2,"'\n", "Diff = '",$count2-$count1,"'\n" ); $text->AppendText( psmem('new f weaken child p destroy') ); } ); Wx::Event::EVT_BUTTON( $frame, $b5, sub {my $count1 = Devel::Leak::NoteSV(my $handle); for(1..100){ my $f = Wx::Frame->new( ($frame ),-1,"goner" ); my $p = Wx::Panel->new( Scalar::Util::weaken($f) ); $f->{p}=Scalar::Util::weaken($p); $p->Destroy; $f->Destroy; undef $p; undef $f; } my $count2 = Devel::Leak::CheckSV($handle); $text->AppendText( join '', "Count1 = '",$count1,"'\n", "Count2 = '",$count2,"'\n", "Diff = '",$count2-$count1,"'\n" ); $text->AppendText( psmem('new f weaken circle child p destroy') ); } ); $frame->GetSizer->Add( $text, 1, Wx::wxEXPAND() ); $frame->GetSizer->Add( $_, 0,0 ) for $b1, $b2, $b3, $b4, $b5; $frame->Show(1); $app->SetTopWindow( $frame ); $text->AppendText( psmem('MainLoop') ); $app->MainLoop; } sub psmem { my ( $msg ) = @_; my @lines = qx{pslist -m $$ 2>NUL}; ## http://live.sysinternals.com/pslist.exe shift @lines for 1..3; chomp @lines; #~ print join "\n", @lines, ""; #~ Name Pid VM WS Priv Priv Pk Faults NonP Page #~ perl 1052 25348 7220 4504 4512 1977 2 33 my %ps; @ps{'Name', 'Pid', 'VM', 'WS', 'Priv', 'Priv Pk', 'Faults', 'NonP', 'Page' } = grep length, split /\s+/, shift @lines; #~ Pri Priority #~ Thd Number of Threads #~ Hnd Number of Handles #~ VM Virtual Memory #~ WS Working Set ------ "Mem Usage" in taskmanager #~ Priv Private Virtual Memory ------ "VM Size" in taskmanager #~ Priv Pk Private Virtual Memory Peak #~ Faults Page Faults #~ NonP Non-Paged Pool #~ Page Paged Pool #~ Cswtch Context Switches #~ use DDS; Dump(\@lines , \%ps); #~ print "VM: $ps{VM} RSS: $ps{WS} - $msg\n"; return "VM: $ps{VM} < WS: $ps{WS} VM: $ps{Priv} > $msg\n"; } __END__ Perl 5.016001 Wx 0.9922 wxWidgets 2.9.4 VM: 53420 < WS: 21900 VM: 19624 > MainLoop Count1 = '34745' Count2 = '35050' Diff = '305' VM: 53420 < WS: 23084 VM: 20632 > new f weaken circle child p destroy Count1 = '34750' Count2 = '35050' Diff = '300' VM: 53420 < WS: 23088 VM: 20632 > new f weaken circle child p destroy Count1 = '34750' Count2 = '35050' Diff = '300' VM: 53420 < WS: 23088 VM: 20632 > new f weaken circle child p destroy Count1 = '34750' Count2 = '34950' Diff = '200' VM: 53420 < WS: 23088 VM: 20632 > new f weaken child p destroy Count1 = '34750' Count2 = '34950' Diff = '200' VM: 53420 < WS: 23100 VM: 20640 > new f child p destroy Count1 = '34750' Count2 = '35150' Diff = '400' VM: 53420 < WS: 23220 VM: 20728 > new f child p Count1 = '35150' Count2 = '35550' Diff = '400' VM: 53420 < WS: 23444 VM: 20924 > new f new p Count1 = '35550' Count2 = '35950' Diff = '400' VM: 53420 < WS: 23664 VM: 21120 > new f new p Count1 = '35950' Count2 = '36350' Diff = '400' VM: 53420 < WS: 23880 VM: 21316 > new f new p