Is there a class that does garbage collection for C++. I was thinking something like:
class A : public GarbageCollected<A>
{
void kill()
{
GarbageCollected<A>.set_cleanup_flag();
}
...
private:
GarbageCollectedPointer<B> b_pointer; // Somehow we follow
GarbageCollectedPointer<B> b_pointer2; // these pointers.
};
class B
{
...
};
class GarbageContainer
{
...
};
int main()
{
GarbageContainer gc;
gc.add(new A());
...
}
The idea being that GarbageContainer
would do mark and sweep on the objects or some other garbage collection method. It would save having to do reference counting and using weak_ptrs and garbage collection could be used just for objects it is felt necessary.
Are there any libraries that implement something like this?