In taking a look at your scratchpad, I don't immediately see the cause of your memory leak, but I see something that should help.

At the top of your code, you've predeclared all of your variables. This means that, regardless of where they are used, they exist. For example, you only use $hd_key in your &Setup_Config subroutine. This means that you should only declare it there, and preferably (though some argue this point) you should only declare it right before you use it. This means that all variables should have the smallest possible scope. You have, in effect, used global variables and eliminated part of the benefit of using strict. Consider the following example:

my $foo; sub bar { # lots o' code $foo++; # more code } sub baz { # do a few laps around the pool ($foo) = (split)[2]; # shower and go home }

In the above example, we've reused the variable $foo. For what good? Is it really necessary? This will confuse someone coming to maintain it later. Further, when the subs exit, $foo hangs around when it may not need to. Here's an example of a nice variable declaration:

sub versive { # some pushups while ( my ($key,$value)= each %data ) { # process things } # }

In that example, $key and $value exist only in the while loop. This means that the memory they use is available for reuse immediately after the scope of the loop ends (IIRC, the memory is not released back to the OS) and there is no worry about accidentally reusing one of those variables later and possibly having an incorrect value. If you get in the habit of coding like that, your code will be much easier to work with in the long run.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to Re: Re: Re: DBD::CSV Memory Leak by Ovid
in thread DBD::CSV Memory Leak by AcidHawk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.