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

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

Thread Previous | Thread Next
February 15, 2001 10:54
Re: Garbage collection (was Re: JWZ on s/Java/Perl/)
Message ID:
Damien Neil wrote:
> On Thu, Feb 15, 2001 at 08:07:39AM -0300, Branden wrote:
> > I think you just said all about why we shouldn't bother giving objects
> > deterministic finalization, and I agree with you. If we explicitly want
> > free resources (files, database connections), then we explicitly call
> > Otherwise, it will be called when DESTROY is eventually called.
> No, the question of whether Perl 6 wants deterministic finalization
> or not is a separate one.  If it doesn't have it, we will be losing
> a very common Perl idiom:
>   {
>     my $fh = IO::File->new("file");
>     print $fh $data;
>   }

Re-read what you wrote in I
think you've got to decide what you want. Do you want smart GC (without
deterministic finalization) and free resources explicitly on special cases?
Or do you want to keep with common Perl idioms (what probably means

I would say I probably prefer refcounting (with some kind of breaking
circular references algorythm), because I see the advantages it brings pay
its price.

> It's nice to know that when the above block exits, $fh will be closed.
> Remember that "closed" doesn't just refer to freeing the resources
> associated with it -- it also includes flushing buffers and the like.

Just set autoflush, if you're lazy...

> Without deterministic finalization, you will almost always want to
> write the above to include an explicit $fh->close().


> The problem is
> that you can not only count on $fh's DESTROY being called at the end of
> the block, you often can't count on it ever happening.

Anyway, the file would be flushed and closed...

> Consider the
> case where the interpreter dies on a signal, for example -- DESTROY
> methods will quite possibly not be called.

Actually, I think this can be worked around. Can't it catch signals?

> I'm not certain that Perl should lose deterministic finalization.  On
> the other hand, I really wish that Perl had a more modern GC scheme,
> if only so that circular structures could be properly collected.


> In
> the end, however, I don't think that any of our opinions will decide
> this -- either Dan's forthcoming PDD will show how Perl 6 can have
> its cake and eat it too, or Larry will decide.

OK for me.

- Branden

>                         - Damien

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