[Prev][Next][Index][Thread]

Re: Destructors



In article
<Pine.GSO.3.96.1000315111630.13259A-100000@tardis.tardis.ed.ac.uk>, Hugh
Greene <q@tardis.ed.ac.uk> wrote:

> On Wed, 15 Mar 2000, Rob Myers wrote:
> > This is a shamefully basic question, but....
> > I know that for constructors in Dylan I can specialize initialize() or
> > make(), but what can I do for destructors?
> 
> Weeeell, Dylan doesn't have destructors quite the same way as C++ does
> (neither does Java, IIRC).

It does. There is also a standard function --
java.lang.Runtime.runFinalizersOnExit(bool) -- that was added in java 1.1
and does the obvious thing.  The places I've worked on Java projects have
turned this on by default in all programs because otherwise all sorts of
wierd bugs happened...

You can also call java.lang.Runtime.gc() to force a garbage collect at any
time, or java.lang.Runtime.runFinalization() to force immediate
finalization on all unreachable objects.


> Garbage collection means that you don't know
> when your objects will "really" go away and you can't "really" destroy
> them manually.

Garbage collection means that you dont *have* to know ... but like an
automatic transmission in your car, sometimes the programmer knows
somethig the machine doesn't and you *should* be able to override it.  And
so Dylan should rovide standard, portable, ways to do that.

 
> Having said that, Functional Developer (and of course Harlequin Dylan ;-)
> has a "finalize" generic function which fulfils a similar role and some
> other fucntions to control when/how finalize gets called.  It basically
> gets called between all references to an object being removed and the
> memory actually being reclaimed; you can also call it manually.  I don't
> know if Gwydion's d2c and Mindy provide the same.

Not at the moment.  We should, and we should be compatable with FD.  Boehm
even has hooks for it.


> 2) A finalize method with a singleton specialiser is useless, because the
> method itself refers to the object, so the object will never be GCd and
> finalize will never be called on it (unless you do so manually, I
> suppose).

Weak references, anyone?

-- Bruce



Follow-Ups: References: