Well from my GUI experience, memory gains usually comes from creating and destroying objects, and the objects don't have a "zero-ref-count". When that happens, Perl keeps the object in memory because there are still some variables connected to it. It's a hassle.

So you are creating 3 new objects in an interdependent manner, and it's not surprising that Perl dosn't release the memory for reuse.

The first thing to try is to only create 1 of each object, and reuse them over and over, by reconfiguring them with new data on each run. (And undef'ing the previous data)

A second method is to try and reuse the namespace by creating a set of global variables to hold the object, then reusing it. Like:

#globals my $bdbi; my $connector; my $searchio #then later in the sub, don't declare them as lexical, #but reuse the global space sub{ $bdbi = new BEAST_UPDATE(); .......... $connector = new AAFCBLAST; .... $searchio = new Bio::SearchIO(); ..... }

A third thing to try, is just to try and undef everything before you leave the sub. You may need to undef everything related to the objects, and do it before you undef the objects. And since the objects are interrelated, undef the objects in the right order.

The first method is probably your best bet, but the others are sometimes "quick fixes".

Also see Re: Is there a penalty for namespace use? and Memory leaks and reference counting within Perl. and the FAQ item

7.27: How do I clear a package? Use this code, provided by Mark-Jason Dominus: sub scrub_package { no strict 'refs'; my $pack = shift; die "Shouldn't delete main package" if $pack eq "" || $pack eq "main"; my $stash = *{$pack . '::'}{HASH}; my $name; foreach $name (keys %$stash) { my $fullname = $pack . '::' . $name; # Get rid of everything with that name. undef $$fullname; undef @$fullname; undef %$fullname; undef &$fullname; undef *$fullname; } } Or, if you're using a recent release of Perl, you can just use the Symbol::delete_package() function instead.

I'm not really a human, but I play one on earth. flash japh

In reply to Re^3: Memory woes by zentara
in thread Memory woes by Anonymous Monk

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.