----- Original Message ----- From: "rocku" <rock...@gmail.com> To: "Amine" <ami...@colba.net> Cc: <perl-win32-users@listserv.ActiveState.com> Sent: Friday, July 24, 2009 3:20 PM Subject: Re: Perl and memory...
> To answer your first question, take a look at Perl's FAQ: > http://perldoc.perl.org/perlfaq3.html#How-can-I-free-an-array-or-hash-so-my-program-shrinks? > Hello, They wrote: "Memory allocated to global variables can be reused (within your program) by using undef()ing and/or delete()." I have 128 meg free memory on the system where i am testing , now even if i use a global variable and i run the script to fill the array it will take 60 meg bytes, and when i undef the array 18.5 meg bytes will return to the system, now how does Perl doesn't return more memory ? there is still more than 40 meg bytes remaining? And suppose we are using big arrays we will soon get out of memory, is it not a problem ? Regards, Amine. > Amine pisze: Regards, Amine. >> Hi all, >> >> Look at the following >> script: ----------------------------------------------- >> >> use Thread qw(:DEFAULT async yield); sub func >> { >> my @b; >> for ($i=0;$i<1000000;$i++) >> { $b[$i] = 'Perl';} >> <STDIN>; >> undef @b; >> print '@b memory returned..'; >> <STDIN>; >> } >> >> @param = (); >> my $t = Thread->new(\&func, @param); $result = $t->join; >> >> print "End of thread...\n"; >> <STDIN>; >> >> -------------------------------------------------- >> >> On Windows click on Ctrl-Alt-del and click on Performance to look at the >> available memory. When you will run this script and the line print "End >> of thread...\n"; is executed all the memory used will be returned by >> Perl. >> >> But when the line 'undef @b' is executed , all the used memory is not >> returned. (please look on the Task manager)... >> So my question is: >> How can i 'force' Perl to return the used memory ? >> >> >> My second question is this: >> >> Look at the following script: >> >> ----------------------------------------------- >> >> sub func >> { >> my @b; >> for ($i=0;$i<1000000;$i++) >> { $b[$i] = 'Perl';} >> <STDIN>; >> undef @b; >> print '@b memory returned..'; >> <STDIN>; >> } >> >> func; >> func; >> >> print "end ...\n"; >> <STDIN>; >> >> ------------------------------------------------ >> >> >> When you will run this script , you will see that the second call to >> func() does take a lot of time(much more than the first call) , why ? >> >> >> >> Regards, >> Amine. >> >> >> _______________________________________________ >> Perl-Win32-Users mailing list >> Perl-Win32-Users@listserv.ActiveState.com >> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs >> > _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs