memory leaks in perl

Tom Legrady legrady-bJEeYj9oJeDQT0dZR+AlfA at public.gmane.org
Sat May 1 18:22:47 UTC 2004


Rick Delaney wrote:

>On Sat, May 01, 2004 at 08:39:16AM -0400, Stewart C. Russell wrote:
>  
>
>>>   undef $hash{$key}
>>>      
>>>
>>That wouldn't work. That's the same as saying $hash{key} = undef -- it's 
>>    
>>
>
>That's not true.  undef($scalar) frees the memory used by $scalar.
>$scalar = undef will leave $scalar using lots of memory if it was
>previously using lots of memory.
>
>  
>
>>setting the value to undef, not freeing up the key.
>>    
>>
>
>Obviously it doesn't free the key, but it does free the value.  But I'm
>pretty sure delete($hash{$key}) will free the value too.
>  
>

Try 'perldoc -f undef' ....

undef EXPR
undef Undefines the value of EXPR, which must be an lvalue. Use only
on a scalar value, an array (using "@"), a hash (using "%"), a
subroutine (using "&"), or a typeglob (using <*>). (Saying
"undef $hash{$key}" will probably not do what you expect on
most predefined variables or DBM list values, so don’t do that;
see delete.)

etc., etc. etc.

Tom Legrady
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list