From: John Max Skaller (skaller_at_[hidden])
Date: 2001-05-10 14:59:44
I have just uploaded version 1.1 of the Felix garbage collector
with integrated reference counting. I hope this one makes
it into the files section :-)
1) provides a reference counting handle
(smart pointer) class,
2) provides better integration
of the ref counting and garbage
3) Counts calls to 'add_root' and 'remove_root'
so that you can add a root twice, and then
must remove it twice to cancel its root status
GC/Ref counting integration: comments
Consider the following scenario. You have a singly
linked list, with the node destructor deleting the
next node in the list. This (gasp!) recursively
deletes the tail of the list following the node,
before deallocating the storage of the node.
If such a list becomes unreachable, then the collector
will randomly pick a node and delete it, recursively
deleting the tail as before. The problem is, the head
of the list is still there, and the collector will
pick another random node to destroy, which attempts
to delete the tail of the list again: which causes
an attempt to delete a node which has already been deleted.
The algorithm is now adjusted to prevent this problem
occuring. First, during collection, object frames are not deleted
immediately, but posted to a list so as to be reaped
afterwards. Secondly, whenever an object is about
to be finalised, it is flagged 'finalised'.
The 'destroy' and 'decref' routines no longer
attempt to delete an object flagged as finalised,
preventing infinite recursion or the calling of
finalisers on already finalised objects.
Note that the mechanism only works if you use the
collectors built in 'decref' and 'destroy' functions.
[If it was safe to call these functions before collection,
it is safe during collection]
The _intent_ of this change is to allow objects which
are managed with explicit deletion or reference
counting to also be collected, without needing
two versions of the finalisation routine.
Note that while this ensures that pointers to 'finalised'
objects frames remain valid, the objects themselves
may have been destroyed. (So don't do something like
try to add up the values of a list of integers in
the destructor, since the 'next' node may have been
destroyed by the collector).
-- John (Max) Skaller, mailto:skaller_at_[hidden] 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850 checkout Vyper http://Vyper.sourceforge.net download Interscript http://Interscript.sourceforge.net
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk