Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

(tye)Re2: Tracking Memory Leaks

by tye (Sage)
on Aug 15, 2001 at 23:02 UTC ( #105141=note: print w/replies, xml ) Need Help??

in reply to Re: (tye)Re: Tracking Memory Leaks
in thread Tracking Memory Leaks

Please reread what I wrote. I agreed that the memory used directly by the lexical will not be freed. But I wanted to clarify that in many cases this doesn't matter much. For example:

sub foo { my $val; if( @_ ) { $val= shift; } else { undef $val; } return $val; } foo( "x" x 10_000 ); # 10,000 bytes of memory still tied up foo() # those 10,000 bytes now free to be reused foo( \( "x" x 10_000 ) ); # the few bytes needed to store a reference still tied up, # but the 10,000 bytes for the string value itself are # already free to be reused.

Yes, closures never being freed is a bug due to Perl itself making a circular reference. I believe this has already been fixed. Your example code should not leak memory whether you consider it reasonable for that to happen or not. (:

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re2: Tracking Memory Leaks
by perrin (Chancellor) on Aug 15, 2001 at 23:35 UTC
    Sorry to be contradictory. We're both saying pretty much the same thing, with slight variations. Your sample code is a good example, but I think it just shows that anonymous storage ( like \( "x" x 10_000 ) ) gets freed right away. I think it would not be freed if you had used a named scalar for that instead.

    My sample code above does leak. You have to run it in a loop to see it, because it only leaks a little each time.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2022-08-10 16:44 GMT
Find Nodes?
    Voting Booth?

    No recent polls found