[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.
You are right: in case of bad OO designs, it does not work.
Normally (using standard design practices), I would not expect
these situations not to occur.
I think one always has some graph-like structure in mind for
"ownership". This is what you suggest as well...?
Cheers,
Marcel