How perl releases "my" variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How perl releases "my" variable?
# 1  
Old 07-15-2010
How perl releases "my" variable?

I have a question regarding to the following code:

Code:
foreach my $Cnt ( @Cnts ) {
  my $abc = xyx->new();
    do sth...
    aggregatedData->processData($abc);
}

my question is: whether perl will release the memory assign to "my $abc" each time after
processData($abc) is being executed.
If not,will it release the memory after for loop completes?
If still not, how to release the memory explicitly? can I put undef($abc) after
aggregatedData->processData($abc) to free the memory?

I am investigating an memory exhausting issue and I want to free memory of a variable as soon as I finish using it.

Last edited by pludi; 07-16-2010 at 02:20 AM.. Reason: code tags, please...
# 2  
Old 07-16-2010
The memory pointed to by $abc will become marked as "unused" after the loop finishes. However, Perl will not immediately return that memory because
  1. The garbage collector runs at certain intervals (don't know the exact timing)
  2. Perl has the habit of clinging to memory it has allocated in case a later operation will need it.
And anticipating your next question: no, I do not know of any way to force Perl to release that memory.
# 3  
Old 07-16-2010
no you cannot.
your problem is elsewhere, probably in your design.
perl is a very efficient language, I've done some massive stuff with no memory problems.
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Trouble with "|" when creating a variable using perl

greetings, not being much of a perl user i'm having an issue when trying to assign a value to a variable using the following: $StatusRawString=`grep -F -e \'time...\' $Glstat | tail -n 1`; when i execute the perl script i'm using the -w option to get some useful info on how the script is... (5 Replies)
Discussion started by: crimso
5 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies
Login or Register to Ask a Question