develooper Front page | perl.perl5.porters | Postings from October 2001

Perlbug 20000530.008 - DESTROY not called on non-closure CODE objs

From:
Michael G Schwern
Date:
October 29, 2001 19:05
Subject:
Perlbug 20000530.008 - DESTROY not called on non-closure CODE objs
Message ID:
20011029220506.F18053@blackrider
I'm going through perlbugs and I came across this thing about DESTROY
not getting properly called.  Looks like it's still a problem.


(From perlbug 20000530.008)
> Consider the following program:
> 
>     #!/opt/perl/bin/perl -w
> 
>     use strict;
> 
>     sub new {
>         my ($class, $code) = @_;
>         bless $code => $class;
>     }
> 
>     DESTROY {
>         print "In DESTROY...\n";
>     }
> 
>     my $i    = "Hello";
>     my $exit = main -> new (sub {});   # 1)
> 
>     __END__
> 
> This will not print anything at all, indicating that the DESTROY method
> isn't called when $exit goes out of scope - not even on program termination.
> 
> If we change 1) such that new() is called with a closure, for instance
> by changing it to:
> 
>     my $exit = main -> new (sub {$i});   # 1)
> 
> DESTROY is called as soon as $exit goes out of scope. 




-- 

Michael G. Schwern   <schwern@pobox.com>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <perl-qa@perl.org>	     Kwalitee Is Job One
I'm exploring my nipples.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About