develooper Front page | perl.perl5.porters | Postings from December 2004

Alternate approach to ordered global destruction

Thread Next
From:
Elizabeth Mattijsen
Date:
December 8, 2004 03:02
Subject:
Alternate approach to ordered global destruction
Message ID:
f06110408bddc8d02937d@[192.168.56.3]
After the Amsterdam PM meeting yesterday, I was thinking about an 
alternate way to do ordered global destruction.  But I'm not sure 
whether that's the way it is already being done or not.

The basic idea is this:

  sub Foo::DESTROY { print "$_[0][0]\n" }
  $a = bless ['a'],'Foo';
  *a = \$b; # $reference to any scalar will do
  print "END\n";

which produces the output:

a
END

i.e. the object in $a is destroyed because the glob assignment of a 
scalar ref breaks the link between the object and its placeholder in 
the namespace.  And that was the final ref that was keeping the 
object alive.


The extension of this idea would be to walk through all of the active 
namespaces and replace all defined scalars, arrays and hashes with an 
empty counterpart.  This would cause the reference count to be 
decremented, and in most cases objects to be DESTROYed.

This would not handle circular references, but those would then be 
handled in the LIFO manner that ogd.pm currently provides.


Would that make sense?  If so, the only part that I miss is a way to 
find out which active namespaces exist, so that I can walk them all. 
I realize there is something like %INC, but that doesn't handle rogue 
namespace assignments such as $Foo::bar (if there is no module 
"Foo.pm" loaded).



Liz

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