develooper Front page | perl.perl5.porters | Postings from November 1999

Behaviour of final cleanup

Thread Next
From:
Raphael Manfredi
Date:
November 17, 1999 08:48
Subject:
Behaviour of final cleanup
Message ID:
24502.942857281@lod23.gnb.st.com
Could someone point me to an FAQ/perlman page where the behaviour of
Perl is clearly specified with respect to final destruction of objects?

I see some bits of info in perlobj.pod, talking about PERL_DESTRUCT_LEVEL.
I don't know what this means, nor what it controls, nor what LEVEL means
in this context!

A

	grep 'PERL_DESTRUCT_LEVEL' *.pod

does not reveal much, only that it only works when Perl is compiled
with -DDEBUGGING (which is not the case for mine).

I can't decide whether the behaviour I'm facing is a bug, an
accidental misfeature due to implementation quirks, or a documented
limitation.

To solve my problem (lack of DESTROY call), I've done horrors like:

------------------------
#
# I don't understand the way Perl garbage collects its memory when it dies.
# It does not systematically call registered destructors (DESTROY) on objects.
# At least with 5.005_03, which was the version in use when I wrote this.
#
# Therefore, if they forget to call ->db_close on their VDBM::File objects,
# (which is next to impossible if you take an exception and you die) the
# database won't be correctly closed, and the dirty file will remain, forcing
# a recovery next time we start.
#
# Let's do the job ourselves to guarantee them something safe.
#
 
my %remembered;
  
sub remember { my ($obj) = @_; return $remembered{$obj} = $obj }
sub forget   { my ($obj) = @_; delete $remembered{$obj} }
sub END      { foreach my $obj (values %remembered) { $obj->db_close } }
sub DESTROY  { my $self = shift; forget($self); $self->SUPER::DESTROY }
------------------------

I'm reluctant to release a new CPAN module with this kind of hacks.
There must be something I've not understood, clearly.

Raphael

Thread Next


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