On Oct 21, 10:14 pm, [EMAIL PROTECTED] (Dr.Ruud) wrote:
> "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 [EMAIL PROTECTED]
> >> 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."

Thanks.
My real application is in logging numerous sets of results each set
saved in
an anonymous array and those arrays referenced from a master array
called @$arrayREFS
When the results are read I clear the data using
@{$arrayREFS[$index]}=();
but am concerned that Perl's auto-creation of anonymous arrays may not
reuse the memory that was used before and may grab new memory each
time that one is created.

What about
$arrayREFS[$index]=undef;
As an alternative way of deleting the data?


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


Reply via email to