Garbage collection normally isn't done in C++. Code is expected to free objects explicitly (e.g., by using
) or implicitly (when a
goes out of scope).
However, here's an article
] about a garbage collector that I wrote. Objects are created in blocks allocated from pools, and a background garbage collector recovers objects that aren't "claimed" at the application level. This is basically a mark and sweep strategy, but applications must claim in-use objects because the system doesn't manage pointers and therefore can't tell which objects have owners. Applications are still expected to free objects explicitly, so the background garbage collector serves as a backup to recover from memory leaks.