develooper Front page | perl.perl6.language | Postings from February 2001

Re: Garbage collection (was Re: JWZ on s/Java/Perl/)

February 14, 2001 07:25
Re: Garbage collection (was Re: JWZ on s/Java/Perl/)
Message ID:
James Mastros wrote:
> On Wed, Feb 14, 2001 at 10:12:36AM -0300, Branden wrote:
> > Also, I think it would be valid for the programmer to explicitly say ``I
> > would like to DESTROY this object now'',
> I'd think that an extension to delete is in order here.  Basicly, delete
> should DESTROY the arg, change it's value to undef, and trigger a GC that
> will get rid of the arg.

Actually, DESTROY has nothing to do with delete or setting a value to undef.
Well, yes, they are related, but if that was all that matters, every object
could be deleted when I assign a variable to other thing. Delete/set to
undef sets the value of a variable, and DESTROY is called when no more
variables reference that object. The problem is when objects are shared by
many variables. For example:

    $a = new Object();
    $b = $a;
    destroy $a;           ## would call $a->DESTROY()
    $b->doSomething();    ## should die. Note that $b is not undef

The problem is that $b has a reference to an object that was already
destroyed, right? It has nothing to do with `undef', since $b cannot be
undef'ed when I call destroy $a, the object knows nothing about $b, right?

And there would be another problem when the GC tries to collect the memory
used by the object, because it usually calls DESTROY on collected objects.
Calling it for this object would mean calling it twice, what is probably a
very wrong thing to do.

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