Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: GC with finalisation?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Skaller <skaller@m...>
Subject: Re: GC with finalisation?
At 22:09 26/08/99 +0100, Markus Mottl wrote:
>> I seem to have several choices. 
>> 	1) implement reference counting for finalisation

>The main problem with reference counting is speed. 

	I was hoping to avoid it ..

>It is possible to
>resolve circular references in linear time, but the constant overhead
>and the associated memory requirements are simply too large.

	I think this is less of a problem than actually
writing the collector, and then changing all my code
to use it.

>I would leave all the work to the OCaml-GC: use module "Weak" to register
>values (eg.: objects) to be finalized. Then check these arrays from
>time to time and call appropriate finalization functions for objects
>that have been reclaimed.

	That is an interesting idea -- but it won't work,
because the destructor must be called _before_ the object
is destroyed by the system. For example, one of my objects
maintains the table of contents for a document,
and when the object becomes unreachable, it is printed
to a file as HTML. Obviously, the object still has to exist
at this point, and retain all attributes.

	However, your idea of using weak arrays may
be useful after all, if I can create a 'symbol' for the
object, and put that into the weak array: the symbols
contains lists of symbols, representing objects the
object depends on. The collector will now collect
symbols, and by checking the weak array I can
execute destructors, and then release it
for collection (by removing it from a corresponding
'strong' array).

	The problem is: it will be slower than
reference counting, and not be entirely synchronous.
The advantage is it will finalise unreachable 
objects with circular references. Also,
reference counting can be added anyhow,
to make non-circular finalisation synchronous.

	Hmm. Comments?


-------------------------------------------------------
John Skaller    email: skaller@maxtal.com.au
		http://www.maxtal.com.au/~skaller
		phone: 61-2-96600850
		snail: 10/1 Toxteth Rd, Glebe NSW 2037, Australia