3 ms·
Hm I don't get the joke -- the whole point of the GC is to avoid free()? Did the interviewer think someone who could implement a GC wouldn't understand that?
by chubot 4y ago
Hm I don't get the joke -- the whole point of the GC is to avoid free()? Did the interviewer think someone who could implement a GC wouldn't understand that?
There are some GCs where you can free() if you like -- IIRC Boehm GC is one of them -- but it has to be designed for that.
- deleted 4y ago[deleted]
- josefx 4y agoManually calling free sounds like an optimization, especially in a language that does not tag pointer values and as result would leak allocations all over the place.
- samus 4y agoThere's another problem: this kind of GC doesn't know much about the memory layout of the objects it manages, but only the addresses. When it finds a byte pattern in memory that looks like it belongs to the objects it manages, it has to assume they are live. Sprinkling in `free()` whenever it can be judged to be safe helps to minimize this issue.