21 Sep
2004
21 Sep
'04
11:22 p.m.
The problem? It saves a pointer to itself as a parameter, so the collector sees there is still a pointer to it and never collects it or any other objects it points to.
Wouldn't it be more logical if GC simply disregarded any pointers from an object to _itself_ and not count them as pointers?
The correct approach is to save an integer offset relative to a base address instead, as is done by the (roughly equivalent) gc_cleanup class that ships with libgc.
This doesn't strike me as something particularly elegant. Pointers to integers and back sounds like a crime in C, for obvious reasons. Even if you don't try to do arithmetic on them.