On 11 May 2007, at 15:31, James. L wrote:
here is my understand and please verify.
say i have sub parse { return
$array_ref_contain_the_data }
does that memory used by the
$array_ref_contain_the_data can be reused by other
mod_perl application too? or it is used only by the
particular $array_ref_contain_the_data?
The memory used by the content of the array will stay allocated until
the reference count for the anonymous array goes to zero. As long as
you have a reference to the data the memory will remain allocated.
Once the reference count goes to zero that memory will be freed for
use by Perl.
It's only storage directly attached to a scalar that hangs around for
subsequent re-use.
So your $array_ref_contain_the_data will continue to occupy memory -
but it's just a few bytes. The data in the actual array will be freed
when there are no longer any references to it.
I'm not sure if this helps but give it a try:
Consider that many things may refer to your array data:
$pork = [ 1, 2, 3 ];
$beef = $pork;
Neither $pork nor $beef has exclusive ownership of the anonymous
array - so neither of them can sensibly attempt to hang on to that
storage for subsequent use. The only thing that's private to a scalar
is its own allocated storage. /That/ memory may be left allocated to
the scalar on the assumption that it might be needed again.
In comparison the memory owned by the [ 1, 2, 3 ] anon array is bit
of a free spirit and can't reasonably be owned by any of the things
that refer to it. It remains allocated until nothing refers to it
and then is freed.
--
Andy Armstrong, hexten.net