Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Memory leak question

by SBECK (Pilgrim)
on Oct 04, 2010 at 18:33 UTC ( #863405=perlquestion: print w/ replies, xml ) Need Help??
SBECK has asked for the wisdom of the Perl Monks concerning the following question:

Date::Manip has a memory leak that I'm trying to track down, and I guess that I simply do not understand perl internals enough to understand what is causing the leak.

A trivial test script:
   #!/usr/bin/perl -w
   use Date::Manip::Date;
   $date = new Date::Manip::Date;
   use Devel::LeakTrace::Fast;
   $date->parse("2010-02-01 01:02:03");
shows:
   leaked SV(0x0x1241a80) from /home/sulbeck/local/lib/perl5/5.10.1/Date/Manip/TZ/amnew_00.pm line 39
This is just one leak among many, but I figure if I can just understand one of them, I'll be able to figure out the others. There are a mixture of leaked AVs, SVs, and RVs if that matters all being reported at the same line 39.

The referenced line 39 in amnew_00.pm looks like:
   %Dates         = (
      1    =>
        [
         [ 1,1,2,0,0,0,1,1,1,19,3,58,'-04:56:02',-4,-56,-2,
          'LMT',0,1883,11,18,16,59,59,1883,11,18,12,3,57,
          '0001010200:00:00','0001010119:03:58','1883111816:59:59','1883111812:03:57' ],
        ],
   ...
);
(there are a number of other hash elements too, but they are all of this format).

This code is used exactly once in Date::Manip::TZ:
   no strict 'refs';
   ...
   my $mod   = $$self{'data'}{'Module'}{$zone};
   eval "require Date::Manip::TZ::${mod}";
   my %dates = %{ "Date::Manip::TZ::${mod}::Dates" };
   $$self{'data'}{'Zones'}{$zone} =
     {
      'Dates'    => { %dates },
     };
   ...
   use strict 'refs';
There are no circular references at this point (in previous versions, there were, but in the development version I'm working on now, I've removed them). I can provide the development version to anyone who wishes it.

I'll be happy to provide any additional information needed

Comment on Memory leak question
Re: Memory leak question
by BrowserUk (Pope) on Oct 04, 2010 at 19:40 UTC

    Reading between the lines of Devel::LeakTrace::Fast's description,

    At END time Devel::LeakTrace::Fast identifies any remaining variables, and reports on the lines in which the came into existence.

    Doesn't the fact that %Dates is a global: use vars qw(%Dates %LastRule);, mean that it won't be cleaned up automatically before END time, and is therefore designated "a leak"?


    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.
      That was rather dumb of me...

      I'm sure you're right. Unfortunately, this just means I have to dig deeper (and probably learn to use the tools better), because Date::Manip DOES have a memory leak, I just haven't correctly identified it yet.

        I sympathise. Tracking down leaks is a pain.

        One possibility to make your life easier, would be to add END blocks in those of your modules that use globals, to undef them.

        That should ensure that they've been cleaned up before the END block in D::L::F runs, and (perhaps) prevent a bunch of false positives and allow you to concentrate on what is left.


        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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-09-01 07:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (298 votes), past polls