On Monday 05 January 2004 1:37 pm, Rob Dixon wrote:
> Gary Stainburn wrote:
> > I'm working for the first time with object, my $self being a ref to an
> > anonymous hash, i.e.
[snip]
> > 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?
> >
> > Am I also right in thinking that this will happen if I lose the reference
> > in $self by simply running:
> >
> > $self=undef;
>
> Yes. But why do you think you need to write a DESTROY method? It's only
> necessary if the object's destruction must include more than just
> deallocating object data (for instance if a running instance count is
> being kept and needs decrementing). If the method is defined, Perl will
> call DESTROY when it is about to automatically release all of the object
> data anyway.

The full DESTROY will also delete link-list references to/from other blocks of 
track, as well as cascade deletes of fittings (signals, etc) associated with 
that track block section.


>
> By the way, these lines:
>
>   $self->{_Links}=();  # blocks connected to me
>   $self->{_Signals}=();
>
> assign 'undef' to the two hash values. What you mean here is
>
>   $self->{_Links} = [];
>   $self->{_Signals} = [];
>
> but it will probably work as it is since
>
>   push @{$self->{_Links}}, $link
>
> still works if the hash value is undefined: Perl 'autovivifies'
> an empty anonymous array if it hasn't already been done.

Thanks, for this. I hadn't spotted my mistake, but as out pointed out, it was 
working okay.  I've changed the lines to FORCE array type to the refs.

>
> HTH,
>
> Rob

-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000     


-- 
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