(keitai-l) Re: Garbage Collection with i-applo

From: Ben Hutchings <ben.hutchings_at_roundpoint.com>
Date: 04/26/01
Message-ID: <JGEMKINHOOBEFEDLJPKOKEOHCBAA.ben.hutchings@roundpoint.com>
Let me write a quick explanation of this so that the non-programmers
might be able to grasp what this is about.

The information that a program works with is divided up into objects.
Each object requires some memory.  Some programming systems require
programmers to include code that gets rid of objects when they are no
longer needed - this frees the memory for re-use, possibly calling
some other code beforehand (a 'destructor' or 'finaliser').  If they
do this wrongly, the results can be disastrous - the computer can run
out of memory because it fills up with unneeded objects that aren't
freed (a 'memory leak'), or it can crash because an object is freed
and its memory re-used when the object is still needed.

Since it's not always easy to work out when an object is no longer
needed, many programming systems (including Java) provide a 'garbage
collector' which does this while the program is running.  This saves
programmer time and should eliminate the disastrous bugs described
above, but it may slow down the program or increase its memory
requirements (or it may do the opposite - this depends on the
program).  It also means that the time when finalisers run is not
predictable, which can be a problem for objects that are visible to
the user (e.g. a window, whose finaliser erases it from the screen)
or to other programs (e.g. an open file, whose finaliser unlocks
the file so it can be opened by other programs).

Michael Turner wrote:
> Zev Blut writes:
<snip>
> > .... Also, in a later release on the thread there is a mention of
> > disposing objects with the DoJa API.
> >
> > Even in the full Java package there are classes that you need to call
> > dispose() on too... I would not attribute this to not having a
> > garbage collector.
> 
> As I understand it, "dispose" is just a general clean-up/release notion,
> so it doesn't even guarantee memory deallocation.
<snip>

Right.  Objects go on living until some time after there are no more
references to them, at which point they can be finalised and their memory
re-used.  For objects that hold resources that a program may need more
control over the lifetime of, e.g. windows or network connections,
dispose() provides a means of releasing the resource immediately.  Since
whichever code calls dispose() must have a reference to the object, it
counts as still in use, so its memory can't possibly be freed.


[ Did you check the archives?   http://www.appelsiini.net/keitai-l/ ]
Received on Thu Apr 26 11:00:24 2001