A cheap way to release a large chunk of memory back to the OS, once a Perl script is done with it, is to fork and exec the memory intensive code, then somehow store the results to be used later. That way, your original Perl script does not retain the memory, at the expense of extra design considerstions to save the returns from the forked code in a db or file. If you want to keep everything in a single script, the only way it will work is if your data is a big string.
#!/usr/bin/perl -w
use strict;
$| = 1;
{
my $string;
for ( 1 .. 100000 ) {
$string .= ( 'x' x 1000 );
}
print "press enter to release";
<>;
undef $string;
print "undefined but still in scope of sub, hit enter\n";
<>;
# if the variable only goes out of scope.
# you *need* to undef it!
}
print "ok,out of scope, press enter to exit";
<>;
This will not work with arrays nor hashes, but if you can somehow stringify your data, the above may work for you.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|