----- Original Message -----
From: "Michael G Schwern" <[EMAIL PROTECTED]>
To: "K Stol" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Monday, August 18, 2003 2:04 AM
Subject: Re: What the heck is: timely destruction


> On Mon, Aug 18, 2003 at 10:52:50AM -0700, K Stol wrote:
> > After reading most of the messages on timely destruction, I still don't
quite understand what it is. If someone has a spare minute free, could you
please explain?
>
> In perl5 you can write this.
>
> my $Destroyed = 0;
> sub DESTROY { $Destroyed = 1; }
> {
>     my $object = bless {};
> }
> die unless $Destroyed;
> print "That's timely destruction\n";
>
> and expect it to work.  It doesn't die and you reach the final print
> statement.  That's because object are destroyed *immediately* upon their
> falling out of scope so you can trust that the DESTROY method is called
> immediately following the block.
>
> Other languages don't work this way.  Java, for example, cleans up unused
> objects whenever it happens to get around to it.  This means your object
> might be destroyed immediately, or after a few statements have run, or
> stick around until the end of the program.
>
Thanks for your quick reply. I don't know perl and its behaviour that well,
so for my understanding, I'll summarize:

if I understood correctly, the problem is that some objects should be
destroyed *immediately*, and should not wait for the GC. In fact, the
programmer may have never heard about a garbage collecting system at all,
and just *assume* that everything which is out of scope, is destroyed. In
real life, these objects may live somewhere in memory, waiting for the GC,
but in fact are still there, so checking them for being alive will not yield
the correct result.

Is this summary correct?

Klaas-Jan






Reply via email to