Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Hunting for a memory leak

by BrowserUk (Patriarch)
on Aug 07, 2012 at 16:20 UTC ( [id://986024]=note: print w/replies, xml ) Need Help??


in reply to Hunting for a memory leak

If you comment out show_drawing($MW, $ZC); in makeReviewScreen() the leak goes away. So look in show_drawing()

If you comment out the Photo:

my $img = 'fred'; # $MW->Photo( # -data => encode_base64( $small->png ), -format => 'png' # );

The leak goes away.

If you replace the -data option with a -file option and load a small image straight off disk, each iteration leaks by approximately the size of the loaded image.

Conclusion: Tk::Photo doesn't clean up its memory when you undef the Photo object.

I tried adding $img->blank; before the undef, but it made no difference.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: Hunting for a memory leak
by perldough (Sexton) on Aug 07, 2012 at 17:18 UTC

    Thank you for this. I believe I need to start doubting the CPAN modules a little more. With your diagnosis, I went to CPAN and found that the bug is already documented.

    However, contrary to your diagnosis, the documentation says that use of the -file option does not cause this behaviour. Maybe there is something here I can use...

    Thanks again,
    Perldough
      contrary to your diagnosis, the documentation says that use of the -file option does not cause this behaviour.

      Hm. Here are my findings using the -file option:

      [18:25:56.31] C:\test>dir test.png 26/05/2012 11:30 7,133 test.png [18:26:17.25] C:\test>986015.pl start perl.exe 6476 Console 1 29 +,328 K end start perl.exe 6476 Console 1 34 +,652 K end start perl.exe 6476 Console 1 38 +,348 K end start perl.exe 6476 Console 1 38 +,180 K end start perl.exe 6476 Console 1 39 +,324 K end start perl.exe 6476 Console 1 42 +,816 K end start perl.exe 6476 Console 1 45 +,948 K end

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        I didn't mean to challenge your finding; rather, I meant to imply that I could maybe look for a way of coaxing my code into exhibiting the behaviour posted in the bug report in order to eliminate the leak.

        I any case, thanks for taking the time for confirming this.

        Perldough

      Looking in the POD for Tk::Image it says:

      CAVEATS It's necessary to use the "delete" method to delete an image object and free memory associated with it. Just using a lexical variable for storing the image object and letting the variable to go out of scope or setting to undef is not sufficient.

      That said, I tried adding

      $ZC->centerTags($dwg); $img->delete; undef $img;

      And it made no difference.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

      Thank you for this. I believe I need to start doubting the CPAN modules a little more.

      Tk modules are notorious for leaks -- also , if the module builds any kind of tree, and grepping the source for "weak" returns no hits, 97/100 its leaking :)

        That's interesting. Would you mind explaining why that is?

        Perldough

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://986024]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 05:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found