On 10 May 2007, at 22:30, Lionel MARTIN wrote:
No.  Those are two different things.  If you explicitly undef it, the
memory gets handed back to Perl:

undef $foo;

If it just goes out of scope, the memory stays allocated to that variable.

Unless I'm misunderstanding you that's not true. When a value's reference count goes to zero the memory is freed - at least to Perl if not to the OS.

Does a :
$tmp = 1; or a $tmp = undef; or a $#$tmp = -1;
gives the memory back to Perl so that it can use it for other purposes?

$tmp is just a reference, and doesn't take much memory at all.  I'm
not sure how you can clear memory that might be allocated to the
anonymous array, or exactly what perl will do with it when the array
goes out of scope.  You can ask on p5p or perlmonks.org if you're
really interested.

When the array goes out of scope its reference count is decremented. If the reference count goes to zero (implying there are no more references) the memory is released.

Reference counting /usually/ does the right thing - at least in term of Perl's memory - if not the OS's. Circular references will foil it though. For example

$x = \$x;

will mean that $x is not freed until you explicitly break the reference cycle.

--
Andy Armstrong, hexten.net

Reply via email to