"Mr. Shawn H. Corey" schreef:
> kenTk:

>> If I populate @array
>> Then
>> @array=();
>> Is the memory that was used for that array now freed?
>
> Yes, providing no other variable contains those items.  For example:
>
> my @a = qw( a b c );
> my @b = @a;
> @a = ();
>
> Since @b contains everything is @a, its contents are not freed until
> the contents of @b are replaced.
>
>>
>> Similarly
>> If I populate the anonymous array  @{$arrayREFS[$index]}
>> Then
>> @{$arrayREFS[$index]}=();
>> Is the memory that was used for that anonymous array now freed?
>
> Yes but as above.

This comes closer, but still isn't the whole story:

OS-memory allocated by perl (let's call it perl-memory) gets detached
from a container (like a variable) when the container itself is
destroyed, for example when it gets out of scope.
Detaching perl-memory from one container doesn't mean that the
perl-memory becomes "perl-free" (or rather "perl-reusable"), because it
can still be attached to other containers.

Only when perl-memory is no longer attached to any container, it is
possible to mark it as "perl-free".
"perl-free" doesn't mean that it is returned to the OS. Normally it just
remains claimed by the perl process, but can be reused by other
containers.

It also depends on which memory allocation strategy your perl binary
uses, see `perl -V |grep alloc`.

Just assume that perl-the-binary, while running, never gives back memory
to the OS. By coding your Perl properly, you can facilitate it to reuse
some parts of all OS-memory that it ever claimed (so that it doesn't
need to claim even more OS-memory).

-- 
Affijn, Ruud

"Gewoon is een tijger."


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to