How can I remove perl object from memory -


i'm having issues memory usage of perl script wrote (code below). script initiates variables, fills them data, , undefines them again. however, memory usage of script after deleting still way high contain no data.

accoring ps script uses 1.027 mb memory (rss) during first 39 seconds (so before foreach loop). then, memory usage starts rising , ends fluctuating between 204.391 mb , 172.410 mb. however, in last 10 seconds of script (where data supposed removed), memory usage never goes below 172.410 mb.

is there way permanently delete variable , data in in perl (in order reduce memory usage of script)? if so, how should it?

use strict; use warnings;  sleep(30);  $elements = 1_000_000; $max_element = 1_000_000_000; $if_condition = 1;  sleep(5);  %hash = (1 => {}, 2 => {}, 3 => {}, 4 => {});  foreach $key (keys %hash){     if( $if_condition ){         $arrref1 = [ (rand($max_element)) x $elements ];         $arrref2 = [ (rand($max_element)) x $elements ];         $arrref3 = [ (rand($max_element)) x $elements ];          sleep(2);          if(!defined($hash{$key}->{'amplification'})){             $hash{$key}->{'amplification'} = [];         }          push(@{$hash{$key}->{'amplification'}},@{$arrref1});         undef($arrref1);         push(@{$hash{$key}->{'amplification'}},@{$arrref2});         undef($arrref2);         push(@{$hash{$key}->{'amplification'}},@{$arrref3});         undef($arrref3);           sleep(3);          delete($hash{$key});          sleep(5);     } }  sleep(10); 

perl faq 3 - how can free array or hash program shrinks?

you can't. memory allocated lexicals (i.e. my() variables) cannot reclaimed or reused if go out of scope. reserved in case variables come scope. memory allocated global variables can reused (within program) using undef() and/or delete().

on operating systems, memory allocated program can never returned system. that's why long-running programs re- exec themselves. operating systems (notably, systems use mmap(2) allocating large chunks of memory) can reclaim memory no longer used, on such systems, perl must configured , compiled use os's malloc, not perl's.

in general, memory allocation , de-allocation isn't can or should worrying in perl.

see "how can make perl program take less memory?"


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -