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")In reply to (tye)Re2: Tracking Memory Leaks
by tye
in thread Tracking Memory Leaks
by Hrunting
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |