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

Alternate approach to ordered global destruction

Thread Next
Elizabeth Mattijsen
December 8, 2004 03:02
Alternate approach to ordered global destruction
Message ID:
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:


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 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 
"" loaded).


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About