From: Waldemar B. <wb...@sa...> - 2011-03-19 20:40:40
|
Hello! I use windows XP, Windows 7 and win32::GUI 1.06. Problem exists on the both OS`s. It is not problem with win32::GUI but I experienced it just using the module in my application. My application dynamically generates series of windows (potentially unlimited). Each of those is full Win32::GUI object with all the staf: buttons, labels, textfields and so on. Now, the windows can be opened as cascades of the windows so, normally full working application has 100-300 different windows but at one time there can be about 10-20 windows simultaniously. Therefore I need a memory only for the 10-20 windows potentialy. The problem I have is the fact that my application can not use the memory again, so in a relativaly short time memory run out and application stops usually with strange colors on the desktop. Here is the perl script which shows the problem. On my machine the error of "Out of memmory" appeared after a little over 4000 iteration - it depends on the machine. Not always this writing happens - very often just stops with strange background colors (black for the example). My question: Does anybode can show me how I could use the memory of deleted objects again? Please look at the example: The address of the object is going up and up... How to stop it? In the code I just delete the object so it is obvious that the memmory is free for reusing. Strange enough is the fact that the object which contains internal GUI window objects got the same address. What is going on? I was searching the Internet but not succeded - althoug they say in this area Perl sucks. Maybe Perl is not good tool for 'really' big or long working applications because of practical leak of memory? Regards Waldemar ########################## use strict; use warnings; use Win32::GUI qw(); my $i = 0; while ( $i < 50 ) { $i++; my $ch = pakiet1->start( $i ); print "$i:\t",$ch,"\t",$ch->{item},"\n"; $ch->{item}->DESTROY; undef $ch->{item}; undef $ch; print "\t\t\t",$ch if $ch; print "\t\t\t",$ch->{item} if $ch->{item}; print "\n"; } ######################## package pakiet1; sub start { my ( $self, $i ) = @_; my $this = {}; bless ( $this, $self ); $this->{item} = new Win32::GUI::Window( -name => "ch", -text => "window", -size => [ 200, 200 ], -pos => [ 400, 400 ], -visible=> 0, ); for ( my $i = 0 ; $i < 400 ; $i++ ) { $this->{item}-> AddLabel( -name => "labe_$i", -text => "label-$i", -size => [ 180, 20 ], -pos => [ 10, 50 ], ); } return $this; } 1; __END__ |
From: Jeremy W. <jez...@ho...> - 2011-03-21 09:04:49
|
Hi, > I use windows XP, Windows 7 and win32::GUI 1.06. Problem exists on the both > OS`s. What version of Perl are you using? > It is not problem with win32::GUI but I experienced it just using the module > in my application. > > My application dynamically generates series of windows (potentially > unlimited). Each of those is full Win32::GUI object with all the staf: ... I also have a dynamic windows interface, but not as large as yours. > > Here is the perl script which shows the problem. On my machine the error of > "Out of memmory" appeared after a little over 4000 iteration - it depends on > the machine. Not always this writing happens - very often just stops with > strange background colors (black for the example). On my machine, your script hardly leaks at all (Win32::GUI 1.06, Perl 5.8.9). I would need to run your script for at least 100,000 iterations before memory becomes an issue? When you get strange colors it usually means your script is not freeing windows handles (which are created/destroyed automatically by win32::gui). Your script isn't leaking handles either. > My question: Does anybode can show me how I could use the memory of deleted > objects again? Please look at the example: The address of the object is going > up and up... How to stop it? In the code I just delete the object so it is > obvious that the memmory is free for reusing. Strange enough is the fact that > the object which contains internal GUI window objects got the same address. > What is going on? I was searching the Internet but not succeded - althoug they > say in this area Perl sucks. Maybe Perl is not good tool for 'really' big or > long working applications because of practical leak of memory? Perl uses a reference counting methodology for it's memory allocation and memory is only freed when the count gets to zero. If the count never gets to zero (because of a bug or design issue, such as using circular links) then memory will never be freed. Perl is fine for large long running applications. In your example the small memory leak looks like a bug within Win32::GUI. It's likely that the issue you are having in your application is that you are storing references to Win32::GUI objects in different places so the reference count never gets to zero thus the object isn't destroyed. I've found the "big memory problems" are associated with leaking windows handles and GDI objects (open task manager and display these columns, if they keep increasing then you need to work out why). Cheers, jez. |
From: Waldemar B. <wb...@sa...> - 2011-03-21 18:57:38
|
Dnia poniedziałek, 21 marca 2011 o 10:04:43 Jeremy White napisał(a): > Hi, > > > I use windows XP, Windows 7 and win32::GUI 1.06. Problem exists on the > > both OS`s. > > What version of Perl are you using? Perl 8.8 and Perl 10.0 (both ActiveState's) - results the same > > > It is not problem with win32::GUI but I experienced it just using the > > module in my application. > On my machine, your script hardly leaks at all (Win32::GUI 1.06, Perl > 5.8.9). I would need to run your script for at least 100,000 iterations > before memory becomes an issue? When you get strange colors it usually > means your script is not freeing windows handles (which are > created/destroyed automatically by win32::gui). Your script isn't leaking > handles either. Lets call it MAD (memory addressing drift) - i don't claim it is the memory leak - I wrote the word "practicle". I wrote another two cases: one in which Win32::GUI was replaced by DBD::Pg and window by cennection: no MAD efect. But next case is very inetersting: Win32::GUI replaced by Prima GUI - which is independent of OS. Prima works in Windows and Linux. Well to the point! I have no MAD efects, but... I have to add apart of these two undef commands another one: $ch->{item}->close. This method closes windows (and - as it seems to me - clears the memory too ) - no MAD. The most interesting fact in this second case is the behaviour of Prima windows when I comment the close method out. Then I see on the screen all the windows created one after another! And - of course - MAD effect arises. Mayby all the problem is that I do not use in Win32::GUI a similar method to that ->close() ? But I can not find it though. > > > My question: Does anybode can show me how I could use the memory of > > deleted objects again? Please look at the example: The address of the > > object is going up and up... How to stop it? In the code I just delete > > the object so it is obvious that the memmory is free for reusing. > > Strange enough is the fact that the object which contains internal GUI > > window objects got the same address. What is going on? I was searching > > the Internet but not succeded - althoug they say in this area Perl > > sucks. Maybe Perl is not good tool for 'really' big or long working > > applications because of practical leak of memory? > > Perl uses a reference counting methodology for it's memory allocation and > memory is only freed when the count gets to zero. If the count never gets > to zero (because of a bug or design issue, such as using circular links) > then memory will never be freed. But what about my example? If it is bad desined problem I would be happy to see the correction. Then I could correct my application. > Perl is fine for large long running > applications. In your example the small memory leak looks like a bug > within Win32::GUI. Maybe problem lies in a lack of the close function? I wonder if in pure Win32::GUI (no Perl's module but in Windows dlls) there is such a close() method? Maybe wrapping it to Perl Win32::GUI would help me? This is not small problem to me. I have so heavy windows that sometimes it is enaugh to open such a windows 10-15 time to get problem with MAD. > It's likely that the issue you are having in your > application is that you are storing references to Win32::GUI objects in > different places so the reference count never gets to zero thus the object > isn't destroyed. But what about my example? Jez, add a loop which adds to one window say 200 labels or textfields and check what will happend. On my machine it needs 100-150 iterations to blow up. It is not a "theoretical" example I have attached. I believe if I could fix the MAD problem in the simple example then I could repair my application. I suspect it is not problem with the amount of a memory. Perl - in the moment of the MAT catastrophy - takes only 45-55 MBs. It's nothing! > I've found the "big memory problems" are associated with > leaking windows handles and GDI objects (open task manager and display > these columns, if they keep increasing then you need to work out why). I can't fine the windows handles and GDI objects in my task manager - where are they? Thank you Jez! Regards Waldemar |
From: Aldo C. <da...@pe...> - 2011-03-21 09:12:54
|
On 19.03.2011 22:40, Waldemar Biernacki wrote: > My question: Does anybode can show me how I could use the memory of deleted > objects again? see http://sourceforge.net/mailarchive/message.php?msg_id=24270723, it should help with your issue. cheers, Aldo |