[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Aliasing and Garbage Collection


> Some more remarks on the performance overhead of Garbage Collection:
> The overhead of Garbage Collection can be O(#pointercopies).
> Use the following scheme:
>   - when allocating a memory fragment, register the object is shared
>     once "shareCount = 1"
>   - when copying a pointer, register the object is shared once more
>     "shareCount++"
>   - register the release of a pointer.
>     void free { sharedCount--; if (sharedCount==0) { call private free } }

Reference counting is subject to memory leaks when cycles exist. Object A
contains a ptr to B, B contains a ptr to A, but both are unreachable from
the program. They are not reclaimed as both have a sharedCount of 1.

Algorithms which do not suffer from this problem are (I believe)
considerably more expensive.