[Israel.pm] Garbage Collection Question

Yuval Yaari yuval at windax.com
Sat May 8 10:40:26 PDT 2004


Shlomo Yona said:
>> Will Perl automagically get rid of $file after the last line I used it
>> in (in case reference count == 0, of course), or would it be better to
>> set it to undef?
>
> Depending on the scope of $file.
> If $file is still in scope, then Perl's garbage collector will not touch
> it. That is because there is no count 0 for that chunk of
> memory.
>
> Setting the scalar to under fill, however, be useful in some
> implementations of Perl, as it will set the reference count
> to 0.

I wonder if I can use Devel::Peek to check for the refcount of $file.
On one hand, $file is not needed anymore, but on the other hand, $file is
"used" by Devel::Peek.

Anyway, I'll set $file to undef, it could do no harm...





More information about the Perl mailing list