Gary Stainburn wrote:
sub new { my $this=shift; # allow for CLASS->new() my $class=ref($this) || $this; # or $obj->new();
The docs that suggested this are in the process of being deprecated. It is not a
good idea to have objects create other objects with new().
Joseph is right here, but I hope he meant to use the word 'clone' instead of 'create' in the line above.
$blocks{$name}=$self;
Don't do this. You are asking for trouble and lock-ups with a construct like
this.
There are perfectly legit reasons to use this kind of construct. The Flyweight Design Pattern pops into my head immediately. The book Object Oriented Perl covers this well, if you're interested.
Now when I wish to DESTROY the hash, I need to free the memory used by the
hash, including the two arrays _Links and _Signals.
Am I right in thinking that the arrays, along with the scalars will be deleted
by the garbage collector when the references in the hash are deleted?
Yes, but circular references, such as the one I pointed out, will gum up Destroy
as well as, most likely, regular functioning.
Am I also right in thinking that this will happen if I lose the reference in
$self by simply running:
$self=undef;
First you will have to free the circular reference.
I'm not sure what you're saying here Joseph, but I don't think it's accurate. DESTROY() is the traditionally accepted place to do something like break a circular reference and it will work just fine. When the last reference to the object is gone, DESTROY() will be called as part of its garbage collection process. If you break the contained circular references at this point, you can handle them before they become unreachable.
James
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>