in reply to Re^11: Detecting memory leaks.
in thread Detecting memory leaks.

Hi Anon,

I posted on the Wx::Perl Mailing list and got this reply:

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.

Regards

Steve

Replies are listed 'Best First'.
Re^13: Detecting memory leaks.
by Anonymous Monk on May 13, 2015 at 07:19 UTC

    That is easy to say, but there is no code to prove it

    I posted Re^11: Detecting memory leaks. because it disproves that theory, event loop is running, memory is growing

Re^13: Detecting memory leaks. ( Wx::wxTheApp()->ProcessIdle; )
by Anonymous Monk on May 13, 2015 at 07:54 UTC

    Here is $app->Dispatch which is running the event loop manually one event at a time , this should clean up the memory but it doesn't

    update: it finally does, solution is to pair $window->Destroy; Wx::wxTheApp()->ProcessIdle; don't know at what point in wxwidgets history ProcessIdle became required/necessary for memory reclamation, I don't remember needing to do that explicitly, but it seems it has, werid but a solution is a solution :)

    *whew* sanity restored

    #!/usr/bin/perl -- use strict; use warnings; use Wx; my$app=Wx::SimpleApp->new; for(1..10){ for(1..2000){ my $f =Wx::Frame->new; $f->Close; $f->Destroy; undef $f; $app->ProcessIdle; ## CRITICAL ## can also be written as ## Wx::wxTheApp()->ProcessIdle; #~ $app->Dispatch for 1..1000; $app->Dispatch for 1..10; } scalar<>; } __END__

      Hi Anon,

      I actually did $app->Yield, which I guess is similiar to $app->ProcessIdle;,

      However, the key thing was we've now run 90 video tests with no crashes!!

      Thanks a lot for your help, it was nice to know that I wasn't alone. And it was you who directed me to post a bug, which was what brought out this resolution.

      Regards

      Steve.

        Aha, I vaguely recall the existence of Yield :) I'm glad it works in your case, but it doesn't when I replace it with ProcessIdle in the examples I posted, heh