http://qs321.pair.com?node_id=103521


in reply to Tie & Destroy, OOP

If you get rid of your objects before global destruction time, you won't have these problems. One solution is just to make sure that the objects are in an inner lexical scope:

{ my $global = ...; sub doSomething { $global->whatever() } }
Another solution is to deliberately clear object references in an END block:

use strict; $^W++; $|++; package A; sub new { my $self = bless {}, $_[0]; print "construct $self\n"; $self; } # Package destructor sub END { print "in global destruction\n"; } # Object destructor sub DESTROY { print "destroying $_[0]\n"; } package main; our $a = A->new(); END { $a = undef; }