[fpc-devel] Improving Ref Counting

DrDiettrich drdiettrich at compuserve.de
Tue Mar 1 08:33:24 CET 2005


Jamie McCracken wrote:

> A GC needs to trace an object's references to see if anything still
> points to it. How else can it decide whether an object is no longer in use?

GC starts from known alive object references, in static or local
variables, and follows the references in these objects to further
objects. Unused objects never occur in this search, so they need no
special marking or other treatment.

Imagine objects represented as tiles, tied together by reference ropes.
Lift one living tile, and all other living tiles will follow. The tiles
without references from living tiles will be left on the floor. GC does
nothing but lift the known alive tiles, and then sweeps the garbage from
the floor. The references in static and local variables are known to
live, their location is the only thing that a garbage collector has to
know.


>>
> It's very expensive. getmem is quite expensive, and you need it for every
> reference this way.

Okay then use Tlist with preallocation of say half a dozen references - 
that should be efficient for 99% of cases for an individual object's 
references.
<<

Do you realize how much memory consume your suggestions? Talking
abojects, each one increased by a list of references?

I agree that there exist only few references to most objects, perhaps
less than 2 references in average, but the management of the according
lists will cost either time (getmem/freemem) or space (preallocation).

DoDi





More information about the fpc-devel mailing list