Gary Stainburn 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.

OK, but Perl will also cascade the deletes for you unless you have cyclic
references in your data. If you have a doubly linked list then this may be
a problem, as you then have to arrange that object data is destroyed only
if it is referenced from within an 'island' of objects which cannot be
accessed from elsewhere.

Rob




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