From: Andrey <wa...@ma...> - 2009-12-23 09:22:18
|
Hello, Win32::GUI users! I have an application which extensively creates and destroys window controls, such as labels, buttons etc.. To get rid from window control I use Win32::GUI::DestroyWindow, but seems this method is not working properly, see example: ================== use strict; use Win32::GUI(); my $main = Win32::GUI::Window->new(-name => 'Main', -text => 'Perl', -width => 200, -height => 200); $main->AddLabel(-name => "Label", -text => "Hello, world", -left => 20, -top => 20, -notify => 1); sub Label_Click { for (1..1000) { Win32::GUI::DestroyWindow($main->{"Label"}{-handle}); delete $main->{"Label"}; $main->AddLabel(-name => "Label", -text => rand(), -left => 20, -top => 20, -notify => 1); } } $main->Show(); Win32::GUI::Dialog(); sub Main_Terminate { -1; } ============= When I click on label the program creates/destroys control many times. But seems there is huge memory leak, when using this method. Is there any "proper" way do destroy window control? |
From: Jeremy W. <jez...@ho...> - 2009-12-23 21:51:34
|
Hi, What version of Win32::GUI are you using? I don't see any memory leak when running your code? You don't need to do anything to 'destroy' a control, Win32::GUI should do the right thing (see below). The same also applies to windows, you can create/destroy (let them go out of scope) just like normal objects and all memory should be released. Well, I think anyway:) Cheers, jez. use strict; use Win32::GUI(); my $main = Win32::GUI::Window->new(-name => 'Main', -text => 'Perl', -width => 200, -height => 200); $main->AddLabel(-name => "Label", -text => "Hello, world", -left => 20, -top => 20, -notify => 1); sub Label_Click { for (1..10000) { #Win32::GUI::DestroyWindow($main->{"Label"}{-handle}); <--- not need#delete $main->{"Label"}; <- not need.$main->AddLabel(-name => "Label", -text => rand(), -left => 20, -top => 20, -notify => 1); } } $main->Show(); Win32::GUI::Dialog(); sub Main_Terminate { -1; } > From: wa...@ma... > To: per...@li... > Date: Wed, 23 Dec 2009 12:22:03 +0300 > Subject: [perl-win32-gui-users] memory leak problem > > Hello, Win32::GUI users! > > I have an application which extensively creates and destroys window controls, such as labels, buttons etc.. > To get rid from window control I use Win32::GUI::DestroyWindow, but seems this method is not working properly, see example: > > ================== > use strict; > use Win32::GUI(); > my $main = Win32::GUI::Window->new(-name => 'Main', -text => 'Perl', -width => 200, -height => 200); > > $main->AddLabel(-name => "Label", -text => "Hello, world", -left => 20, -top => 20, -notify => 1); > > sub Label_Click > { > for (1..1000) > { > Win32::GUI::DestroyWindow($main->{"Label"}{-handle}); > delete $main->{"Label"}; > $main->AddLabel(-name => "Label", -text => rand(), -left => 20, -top => 20, -notify => 1); > } > } > > $main->Show(); Win32::GUI::Dialog(); > > sub Main_Terminate { -1; } > ============= > > When I click on label the program creates/destroys control many times. But seems there is huge memory leak, when using this method. Is there any "proper" way do destroy window control? > > > ------------------------------------------------------------------------------ > This SF.Net email is sponsored by the Verizon Developer Community > Take advantage of Verizon's best-in-class app development support > A streamlined, 14 day to market process makes app distribution fast and easy > Join now and get one step closer to millions of Verizon customers > http://p.sf.net/sfu/verizon-dev2dev > _______________________________________________ > Perl-Win32-GUI-Users mailing list > Per...@li... > https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users > http://perl-win32-gui.sourceforge.net/ _________________________________________________________________ Got more than one Hotmail account? Save time by linking them together http://clk.atdmt.com/UKM/go/186394591/direct/01/ |
From: Andrey <wa...@ma...> - 2009-12-24 08:15:45
|
Hello Jeremy! I tried your code (with commented lines) and memory leak still exists I tried it under WinXP SP2 and SP3 Perl version: 5.10.0 Win32::GUI version: 1.06 Here is stats for working set and private bytes for script: 1. after start: WS: 1276K, PB: 3668K, Handles: 25 2. first hit on label: WS: 13364K, PB: 14896K, Handles: 25 3. second hit on label: WS: 24676K, PB: 26148K, Handles: 25 ... 4. tenth hit on label: WS: 173 Meg, PB: 116 Meg, Handles: 25 all is ok with handles, but memory is leaking -----Original Message----- From: Jeremy White <jez...@ho...> To: <wa...@ma...>, <per...@li...> Date: Wed, 23 Dec 2009 21:50:15 +0000 Subject: RE: [perl-win32-gui-users] memory leak problem > > Hi, > What version of Win32::GUI are you using? I don't see any memory leak when running your code? You don't need to do anything to 'destroy' a control, Win32::GUI should do the right thing (see below). The same also applies to windows, you can create/destroy (let them go out of scope) just like normal objects and all memory should be released. Well, I think anyway:) > |
From: Kinch <ki...@ne...> - 2009-12-24 08:28:33
|
Without knowing much about perl or it's internals, isn't this behaviour normal for perl, especially on windows? I was told that when perl variables are "freed", the perl interpreter keeps the memory malloc'ed in a pool to use again for any new perl variables or data structures it needs. -----Original Message----- From: Andrey [mailto:wa...@ma...] Sent: Thursday, 24 December 2009 6:15 PM To: Jeremy White; perl-win32-gui-users Subject: Re: [perl-win32-gui-users] memory leak problem Hello Jeremy! I tried your code (with commented lines) and memory leak still exists I tried it under WinXP SP2 and SP3 Perl version: 5.10.0 Win32::GUI version: 1.06 Here is stats for working set and private bytes for script: 1. after start: WS: 1276K, PB: 3668K, Handles: 25 2. first hit on label: WS: 13364K, PB: 14896K, Handles: 25 3. second hit on label: WS: 24676K, PB: 26148K, Handles: 25 ... 4. tenth hit on label: WS: 173 Meg, PB: 116 Meg, Handles: 25 all is ok with handles, but memory is leaking -----Original Message----- From: Jeremy White <jez...@ho...> To: <wa...@ma...>, <per...@li...> Date: Wed, 23 Dec 2009 21:50:15 +0000 Subject: RE: [perl-win32-gui-users] memory leak problem > > Hi, > What version of Win32::GUI are you using? I don't see any memory leak when running your code? You don't need to do anything to 'destroy' a control, Win32::GUI should do the right thing (see below). The same also applies to windows, you can create/destroy (let them go out of scope) just like normal objects and all memory should be released. Well, I think anyway:) > ---------------------------------------------------------------------------- -- This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev _______________________________________________ Perl-Win32-GUI-Users mailing list Per...@li... https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users http://perl-win32-gui.sourceforge.net/ __________ NOD32 4713 (20091223) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com |
From: Andrey <wa...@ma...> - 2009-12-24 08:44:23
|
Memory leak cannot be normal for any program. So, it is either Perl bug or Win32::GUI bug But I noticed that same example using Perl/Tk does not cause memory leak. =================== use strict; use Tk; my $w = MainWindow->new; my $b = $w->Button(-text => 'test', -command => \&click)->pack(); MainLoop; sub click { for (1..10000) { $b->destroy; $b = $w->Button(-text => rand(), -command => \&click)->pack(); } } =================== -----Original Message----- From: "Kinch" <ki...@ne...> To: "'perl-win32-gui-users'" <per...@li...> Date: Thu, 24 Dec 2009 18:28:03 +1000 Subject: Re: [perl-win32-gui-users] memory leak problem > Without knowing much about perl or it's internals, isn't this behaviour > normal for perl, especially on windows? I was told that when perl variables > are "freed", the perl interpreter keeps the memory malloc'ed in a pool to > use again for any new perl variables or data structures it needs. > |