in reply to Re^2: Memory woes
in thread Memory woes
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.
|
|---|