Thank you everyone for your replies and comments. It has been an interesting discussion.
I actually used zentara's suggestion of forking the large memory section so that once the process ended, the memory was returned. This works well and as I was already using Parallel::ForkManager elsewhere in the code I only had to make a couple of changes to the code so thank you!
For those interested, in addition to following Anonymous Monk's advice and passing the $coverage hashref as an argument to the sub, the other changes I made to get this working as I want were as follows:
- Initially adding the use of Parallel::ForkManager and configuring a max of 1 fork
use Parallel::ForkManager;
my $fm = Parallel::ForkManager->new(1);
Inside the foreach loop identify the code to be run within the fork and initiate the fork
foreach my $t (@times){
$fm->start and next;
At the end of the loop, identify the end of the code within the fork and finish the fork. Outside the loop, block the main process until the forked process has finished.
print "what's the mem doing?\n";
sleep(10);
$fm->finish();
}
$fm->wait_all_children();
That's it. The forked process releases the memory when it finishes and the next process starts afresh.
Cheers,
Rich
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.