On Fri, 1 Jun 2001, Scott Alexander wrote:
> Hi,
>
> in my code I have
>
> my @upper_id ;
>
> during the code I pass the array by reference to a sub routine
>
> and push values onto it.
>
> push @{$upper_id}, $row[0] ;
This is odd syntax! Why not just:
push @upper_id,$row[0];
I hope this isn't some sort of soft reference.
> Some of my code I have arrays of strings or ints.
>
> I might add 100 or more items to each array. The strings could be
> 50 characters long.
>
> What happens to the array at the end?
>
> Should I have a
>
> undef @upper_id ;
> at the end ?
>
> If I don't have this does it mean the array just stays in memory until
> the child is stopped?
>
> A the moment the max child life is set at 300.
This is VERY low.
> Any help or pointers would be greatly appreciated.
Fairly tricky question: Answers are my own, gleaned from years of faithful
mailing list reading.
1) It's lexical, so it goes out of scope and is destroyed when that
happens.
2) However, as an optimization, perl pretty much never releases
back to the OS memory once used for variable storage, which saves
on calls to malloc() and free().
3) All memory is freed when the child dies.
So, you don't need to do anything, but you'll never get the memory back
until the child dies.
It will run fast, however. :-)
--
-- Tom Mornini
-- InfoMania Printing and Prepress