Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!newsfeed.internetmci.com!howland.reston.ans.net!Germany.EU.net!news.maz.net!ins.net!heeg.de!uucp
From: Hans-Martin Mosner <hmm@heeg.de>
Subject: Re: Garbage collection in ST
Content-Type: text/plain; charset=us-ascii
Message-ID: <310746ED.2781E494@heeg.de>
Sender: uucp@heeg.de
Content-Transfer-Encoding: 7bit
Organization: Georg Heeg Objektorientierte Systeme
References: <DLp9M8.93r@cunews.carleton.ca>
Mime-Version: 1.0
Date: Thu, 25 Jan 1996 09:01:33 GMT
X-Mailer: Mozilla 2.0b5 (X11; I; SunOS 4.1.3 sun4c)
Lines: 50

Evan Hughes wrote:
> 
>  Would it be possible to allow for user-controlled garbage collection in
> Smalltalk? Ie, could you set up constructors and destructors like in C++?
> 
> Evan Hughes
> Honours Computer Science
> http://chat.carleton.ca/~ehughes

Constructors are there all over the system. Many classes implement
#new as '^super new initialize', using the #initialize method for
construction.
Destructors can be written. Standard Smalltalk practice is to have
a #release method when you want explicit destruction. However, this
does not free the memory allocated to the object. That is only done
when all references to it have disappeared, and it is the job of the
garbage collector to detect this.
In the old days, when GC was being done with reference counting, the
#release mechanism would serve to break reference cycles. Nowadays it
is almost always unneeded, as all Smalltalk systems have more
sophisticated GC schemes.
In the case of a generational garbage collector, it can help a little
when references from older to newer objects are broken, but you
normally don't have an idea what the garbage collector considers as
'old' or 'new' objects.

That said, there are still more things you can do:
If all you want is to make sure that unneeded space is being reclaimed,
you can just invoke the garbage collector. In VisualWorks, for example,
all but the most low-level garbage collection operations are explicitly
invoked by methods in the image, thereby giving you a chance to
implement your own policies. When you know you're done with a big
object, you might just call 'ObjectMemory garbageCollect' or one of
the variants.
If you need to be notified when an object is not being referenced
anymore, some Smalltalk systems can give you that information, too.
Note that they don't tell you that an object is about to disappear,
but that it has already disappeared. You would need to remember any
information needed for cleanup in some other object. Look at VisualWorks'
finalization mechanism to see how it is being used. This mechanism
is normally only used when the object in question has a handle to some
external resource that must be freed when the object does not exist anymore.

Hans-Martin

-- 
+--- Hans-Martin Mosner -------- Senior Smalltalk Guru ---+
| These opinions are entirely ficticious.  Any similarity |
| to real opinions is purely coincidental and unintended. |
+--- <hmm@heeg.de> ------ URL:http://www.heeg.de/~hmm/ ---+
