Re: Wx::Perl seems to be leaking memory
Steve Cookson <[email protected]> Mon, 11 May 2015 13:05:06 -0300
| Newsgroups | gmane.comp.lang.perl.wxperl |
|---|---|
| Message-ID | <[email protected]> |
Hi Mark,
Thanks for this. So the short answer was that I had indeed made a
fundamental error. I should update PM.
Maybe I knew all this once upon a time, but I had definitely forgotten
it long since!! It explains why I had leaks all over the place. Some
of which must have been quite big because of embedded scrolling photos
and other stuff.
Can I just clarify what is meant by "toplevel". I guess it means
anything that groups controls that you would normally expect to disapear
because of going out of scope: any Dialog, Panel or Frame with children
or indeed a tree of descendants. Or does it just mean the application
main frame?
And if a whole tree goes out of scope simultaneously, eg controls in
sizers on panels within panels in a dialog, is it enough to Destroy the
dialog?
Thanks again,
Regards,
Steve.
On 11/05/15 11:52, Mark Dootson wrote:
> 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.
>
>