Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: Memory leak question

by SBECK (Hermit)
on Oct 05, 2010 at 13:30 UTC ( #863598=note: print w/replies, xml ) Need Help??


in reply to Re^3: Memory leak question
in thread Memory leak question

Thanks for an extremely useful suggestion. I have done this and a lot of the extra results are gone. However, there is still a memory leak. However, now I'm not sure whether it's Date::Manip, or perl.

If I replace the parse in the script above with:
   for (1..100) {
      $date->parse("2010-02-01 01:02:03");
   }
I get the following output:
   leaked SV(0x0x1300100) from /home/sulbeck/local/lib/perl5/5.10.1/Date/Manip/TZ/amnew_00.pm line 44
   leaked RV(0x0x1250200) from /home/sulbeck/local/lib/perl5/5.10.1/Date/Manip/TZ/amnew_00.pm line 44
   leaked SV(0x0x12d0300) from /home/sulbeck/local/lib/perl5/5.10.1/Date/Manip/Date.pm line 1115
   leaked SV(0x0x1310200) from /home/sulbeck/local/lib/perl5/5.10.1/Date/Manip/TZ/amnew_00.pm line 44
   leaked RV(0x0x12d0000) from /home/sulbeck/local/lib/perl5/5.10.1/Date/Manip/TZ.pm line 163
   leaked SV(0x0x1320300) from /home/sulbeck/local/lib/perl5/5.10.1/Date/Manip/TZ/amnew_00.pm line 44
   leaked SV(0x0x12a0100) from /home/sulbeck/local/lib/perl5/5.10.1/Date/Manip/Date.pm line 1115
   leaked SV(0x0x12e0100) from /home/sulbeck/local/lib/perl5/5.10.1/Date/Manip/TZ/amnew_00.pm line 44
   leaked SV(0x0x1320000) from /home/sulbeck/local/lib/perl5/5.10.1/Date/Manip/TZ/amnew_00.pm line 44
   leaked SV(0x0x12f0100) from /home/sulbeck/local/lib/perl5/5.10.1/Date/Manip/TZ/amnew_00.pm line 44
So, even though I've got a couple leaks, it's not leaking at every iteration. It appears that there are a couple of 'one-time-only' leakes, and I'd be willing to ignore them if I can't resolve them in a reasonable amout of time.

Unfortunately, if I just repeatedly parse the same date (i.e. do 1000000 iterations instead of 100) and monitor the size of the perl executable while it is running, it keeps growing.

Since running for 100 iterations shows only the 10 "leaks" above, but running over many iterations shows the executable continually growing, does this indicate that maybe the problem isn't (directly) with Date::Manip? Or is this just wishful thinking?

Thanks

Replies are listed 'Best First'.
Re^5: Memory leak question
by BrowserUk (Pope) on Oct 05, 2010 at 15:18 UTC
    does this indicate that maybe the problem isn't (directly) with Date::Manip?

    You might be right.

    One source of leaks is the routine _iso8601_rx(). If you modify it:

    sub _iso8601_rx { return ''; ...

    This doesn't leak any more:

    #!/usr/bin/perl -slw use Date::Manip::Date; $date = new Date::Manip::Date; #use Devel::LeakTrace::Fast; for (1..100e6) { $date->parse("2010-02-01 01:02:03"); }

    Now that routine uses an extensive given/when construct, which I've had problems with in the past. And I think I've read other bug reports alluding to memory leaks associated with that construct previously.

    To confirm my suspicion, I commented out the given( $rx ) { line and closing brace, and replaced all the whens with an if/elsif/else cascade. The result was that the rate of memory leak reduced markedly. Perhaps to 1/10 of the rate.

    You do have 6 other given/when constructs in the file and I strongly suspect that if you replaced those similarly with if/elsif/else cascades, your memory leaks would abate even further, if not completely.


    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.
      WOW!!! I didn't expect you to do my debugging for me, but I really appreciate your help!

      Although I like the syntax of the given/when better... it's not a big enough deal to me to fight with memory leaks over. I'll make all of the switches and be ready to test it out later today.

      Thanks again.

        NP. I really didn't do that much. I just looked inside to see if anything rang any bells, and the given/when thing did.

        But I was unsure of my memory, so I made the changes I described to confirm them before reporting them. I didn't want to groundlessly poison the construct.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2019-04-18 10:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I am most likely to install a new module from CPAN if:
















    Results (102 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!