Gary Stainburn wrote:

> Hi folks,
>
> I'm working for the first time with object, my $self being a ref to an
> anonymous hash, i.e.

Couple not so good things here.

>
>
> 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().  I'll have more later
on this, if others don't fill in the blanks in the meantime.

>
>   my ($name,$type)[EMAIL PROTECTED];
>   my $self={};
>   bless $self,$class;
>   $self->{_Name}=$_[0]; # name of track block section
>   $self->{_Type}=$_[1]; # type of block
>   $self->{_Links}=();  # blocks connected to me
>   $self->{_Signals}=();
>   $blocks{$name}=$self;

Don't do this.  You are asking for trouble and lock-ups with a construct like
this.

>
>   return $self;
> }
>
> 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.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to