Re: Wx::Perl seems to be leaking memory

Steve Cookson - gmail <[email protected]> Wed, 20 May 2015 17:49:00 -0300
Newsgroups gmane.comp.lang.perl.wxperl
Message-ID <[email protected]>
On 14/05/15 15:24, Steve Cookson wrote:
> That has been a very painful lesson.  We've now run over 60 video 
> tests with no crashes, so I hope it is resolved. 

I spoke too soon: the crashes have just moved to a different part of the 
system.

I've cut down a piece of code to try to isolate the problem and it 
follows this email.

If I create a few controls in a dialog, delete the dialog, use 
$app->Yield for the background processing to take place, I still end up 
with more Perl objects after the deletion than before.

Any ideas welcome.

Regards

Steve

#! /usr/bin/perl

package main;
use strict;
use warnings;

$main::app = App->new();
$main::app->MainLoop;

package App;
use strict;
use warnings;
use base 'Wx::App';


sub OnInit {

     Wx::InitAllImageHandlers();
     my $frame = Launch->new();
     $frame->Show(1);

}

package Launch;
use strict;
use warnings;
use Wx qw(:everything);
use base qw(Wx::Frame);
use Devel::Leak;
sub new {
     my ($class, $parent) = @_;


     my $i_frame = $class->SUPER::new($parent, -1, "Test", 
wxDefaultPosition, wxDefaultSize);
     $i_frame->{panel} = Wx::Panel->new($i_frame, -1, wxDefaultPosition, 
wxDefaultSize);
     $i_frame->{sizer} = Wx::BoxSizer->new(wxVERTICAL);
     $i_frame->{button} = Wx::Button->new($i_frame->{panel}, -1, 
"Launch", wxDefaultPosition, wxDefaultSize);
     $i_frame->{sizer}->Add($i_frame->{button});
     $i_frame->{panel}->SetSizer($i_frame->{sizer});
     $i_frame->{panel}->Layout();
     Wx::Event::EVT_BUTTON( $i_frame, $i_frame->{button}, sub {
     my ($self1, $event1) = @_;
     my $count1 =  Devel::Leak::NoteSV(my $handle);
     my $frame = Dialog->new();
     $frame->ShowModal();
     $frame->Destroy();
     $main::app->Yield();
     my $count2 =  Devel::Leak::CheckSV($handle );
     print $count1, "\n";
     print $count2, "\n";
     print $count2-$count1, "\n";
     });
     return $i_frame;

}
package Dialog;
use strict;
use warnings;
use Wx qw(:everything);
use base qw(Wx::Dialog);

sub new {
     my ($class, $parent) = @_;

     my $frame2 = $class->SUPER::new($parent, -1, "Test i_Layout" , 
wxDefaultPosition, wxDefaultSize);
     $frame2->{panel2} = Wx::Panel->new($frame2, -1 , wxDefaultPosition, 
wxDefaultSize, );
     $frame2->{sizer2} = Wx::BoxSizer->new(wxHORIZONTAL);
     $frame2->{panel2}->SetSizer($frame2->{sizer2});
     $frame2->{panel2}->Layout();

     return $frame2;

}
1;