Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Re: Re: Memory Management and Array references

by hv (Parson)
on May 25, 2004 at 21:58 UTC ( #356396=note: print w/ replies, xml ) Need Help??

in reply to Re: Re: Memory Management and Array references
in thread Memory Management and Array references

Any structure will be freed in perl when the last reference to it goes away; in your iterator, when you've exhausted the top-level directory and start working on the next you have:

if( opendir( DIR, $dir ) ) { $self->{files}= [ map { File::Spec->catfile( $dir, $_ ); } File::Spec->no_upwards( readdir(DIR) ) ]; closedir DIR; } else { ... {

At that point, when you assign a new arrayref to $self->{files}, the previous arrayref in that spot is overwritten and therefore its reference count is reduced - if that was the only reference to the previous arrayref, it will automatically be freed.

So, to free unneeded memory in perl all you need to do - all you should do - is precisely to remove all references to the data.

I suspect therefore that the problem is not where you think it is. I suggest that you step back and compose a new question - start off by telling us what makes you think you are leaking memory, and what in the process of tracking that down led you to believe the problem lay here.


Comment on Re: Re: Re: Memory Management and Array references
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://356396]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2015-11-26 07:38 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (696 votes), past polls