previous | start

C Problems for Garbage Collection

In C an integer variable can hold an address (cast a pointer to an int).

So a garbage collector for C could not be certain that only pointers hold references to heap memory.

So it would have to assume that an integer value that happens to coincide with a heap memory address means that heap memory is reachable and should be marked.

This results in a conservative garbage collector.

That is, a conservative garbage collector guarantees that any heap location that is reachable will be marked. But some heap locations may be marked that are not reachable and are really garbage.

So a conservative garbage collector may not collect all the garbage, but it definitely won't collect items that are NOT garbage.



previous | start