Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^8: Detecting memory leaks.

by Steve_BZ (Chaplain)
on May 07, 2015 at 09:30 UTC ( #1125978=note: print w/replies, xml ) Need Help??


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

Hi Anon,

Ok, I ran it and I get a huge list of stuff like this:

new 0x492bdd8 : new 0x36031a0 : new 0x2930a58 : new 0x2909af8 : old (1): 0 old (1): 0 old (1):

I guess they are new octal addresses. The counts seem very high, this is what I get:

my $mu = Memory::Usage->new(); $mu->record('before add appointment'); my $count1 = Devel::Leak::NoteSV(my $handle); __new_appointment($self1, $event1); my $count2 = Devel::Leak::CheckSV($handle ); print $count1, "\n"; print $count2, "\n"; print $count2-$count1, "\n"; $mu->record('after add appointment'); $mu->dump(); __END__ 595269 596072 803 time vsz ( diff) rss ( diff) shared ( diff) code ( diff) + data ( diff) 0 772200 ( 772200) 195796 ( 195796) 43708 ( 43708) 8 ( + 8) 369168 ( 369168) before add appointment 33 794160 ( 21960) 217104 ( 21308) 43972 ( 264) 8 ( +0) 390508 ( 21340) after add appointment

How can I track down these addresses?

It's a bit above my pay grade!

Regards

Steve.

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

    Well, you keep sticking notesv/checksv around chunks of code until you narrow it down, then do a code review looking for references

    Or you could try Devel::Cycle which will at least tell you what kind of cycles it found

      Hi Anon,

      So using your narrow review method, the following (ie one function using a hash object)

      my $count1 = Devel::Leak::NoteSV(my $handle); $booking_dlg->{booking_main} = Wx::Panel->new($booking_dlg +, wxID_ANY, wxDefaultPosition,[$gl_cfg->{monitor_resolution_x}, $gl_c +fg->{monitor_resolution_y}], wxNO_BORDER, "" ); my $count2 = Devel::Leak::CheckSV($handle ); print "Count1 = '",$count1,"'\n"; print "Count2 = '",$count2,"'\n"; print "Diff = '",$count2-$count1,"'\n";

      Gives me:

      new 0x9d741e8 : new 0x9d56f70 : new 0x9d44858 : new 0x9d38270 : new 0x9d382d0 : old (1): 0 Count1 = '594970' Count2 = '594974' Diff = '4'

      Maybe I'm using the wrong mental model, but I don't really see how this could be, unless there are new objects being created by Wx::Panel, which are then referred to by references in $booking_dlg->{booking_main} and therefore not dropping out of scope.

      What do you think?

      Regards

        You are passing in $booking_dlg to Wx::Panel::new, which is presumably creating a Wx::Panel object, which recursively refers to at least 3 other objects. If any of these other objects saves the reference to $booking_dlg, then you have a circularity of the form:
        $booking_dlg->{booking_main} == Wx::Panel object, (Wx::Panel object)->{foo} == other object (other object)->{bar} = $booking_dlg
        which will preserve the Wx::Panel object, the other object, and the $booking_dlg object forever unless ->{booking_main} gets reassigned sometime later. (and if $booking_dlg is simply being tossed later on, there's your leak right there)

        (Update:  Well, okay, it could also be (Wx::Panel object)->{foo} = $booking_dlg directly and the other 3 objects are just being dragged along for the ride. It only takes one such reference to ruin your day...)

        Umm

        I think something went wrong , things seem different from what I remember and from what it apparently is, I'm unsure of stuff now

        Consider this program

        "new f new p" is not supposed to leak 400 scalars

        "new f child p" is not supposed to leak 400 scalars because the reference is supposed to be a weak reference

        "new f child p destroy" is not supposed to leak 200 scalars, circular reference or no circular reference, Destroy is supposed to clean them all up

        ...

        So maybe this is just taskmanager lying to me, or Devel::Cycle lying, or I'm really mis remember how this used to work or how its supposed to work, but I'm pretty sure this is a bug that needs to be reported to rt://Wx :) you should report it

        Heck, consider these oneliners

        My winxp taskmanager tells me memory keeps increasing with these programs ... well its pretty much not supposed to

        Dang

      Hi Anon,

      Thanks for your continuing interest!

      Is there some way I can decode the octal references and therefore maybe step through any arrays or hashes looking for content?

      Regards.

        Maybe, i never tried, i got by with narrow/review. why not try the other mod?

      then do a code review looking for references

      looking for CIRCULAR references which you can Scalar::Util#weaken

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2023-01-30 17:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?