Re: Wx::Perl seems to be leaking memory

Mark Dootson <[email protected]> Mon, 11 May 2015 15:52:55 +0100
Newsgroups gmane.comp.lang.perl.wxperl
Message-ID <[email protected]>
Hi,

See 
http://docs.wxwidgets.org/3.0/classwx_window.html#a6bf0c5be864544d9ce0560087667b7fc

details for wxWindow::Destroy.

As you have determined, top level windows you create need to be 
destroyed with $win->Destroy;

The C++ structure for a Wx::Frame contains a reference to the associated 
Perl SV. So that SV won't go away until the C++ structure is deleted - 
which will never happen until your event loop is running.

Hope this helps.

Mark


On 11/05/2015 14:32, Steve Cookson wrote:
> Hi Guys,
>
> I started to talk about this on Perl Monks, you may have seen it here:
>
> http://www.perlmonks.org/?node_id=1125580
>
> An anonymous monk posted some code that showed just about every call 
> to Wx leaking a scalar or two.  I've played about with the posted code 
> and there is a copy attached to this email.
>
> The main part of the code, here:
>
>         $count1 =  Devel::Leak::NoteSV($handle);
>         for(1..100){
>             my $f=Wx::Frame->new( undef ,-1,"goner" );
>             my $p=Wx::Panel->new (undef ,-1 );
>             #my $b=Wx::Button->new ( $f ,-1 );
>             #my $t=Wx::TextCtrl->new($f, -1, "");
>             #$t->Destroy;
>             #$b->Destroy;
>             #$i->Destroy;
>             $p->Destroy;
>             $f->Destroy;
>         }
>
>         $count2 =  Devel::Leak::CheckSV($handle);
>
> seems to show that if you do not ->Destroy a Wx object, it will not go 
> out of scope naturally and even if you do destroy a Wx::Frame object, 
> it will not go out of scope.  The monk also tried Weaken and undef, 
> with the same results.
>
> Please have a look at this and make sure that I have not (or the 
> Anonymous Monk has not), made some fundamental error.
>
> I have checked it both in 2.8.11 and 3.0.2 with the same results.
>
> I look forward to hearing your feedback,
>
> Regards
>
> Steve.