Reputation: 18574
What garbage collectors are there available for C++? Are you using any of them? With what results?
Upvotes: 6
Views: 731
Reputation: 24557
You can find several implementations here. I have never tried any of them and in general I find a non-deterministic GC causing more harm than good.
Upvotes: 2
Reputation: 56448
There's always, ahem: C++/CLI -- C++ for the .NET Framework. Pretty good garbage collection there. :p
Although, to be honest, with all the syntactic sugar they put in there, you could almost consider it a whole new language that just happens to work with C/C++ fairly well.
If you're not married to C++ as a language, you could also look into D, which compiles to native code like C++ (and unlike C++/CLI) but also has garbage collection.
Upvotes: 2
Reputation: 134
The Boehm garbage collector is pretty good for C, but tricky to use under C++. Check the "C++ interface" section at http://www.hpl.hp.com/personal/Hans_Boehm/gc/gcinterface.html.
My opinion is that if you need garbage collection, choose a langage that has it built-in.
The best general solution for C++ is shared pointers (from boost for example) with you dealing with circular dependencies. There are two things you can do: 1. design the thing with no circular dependencies 2. design the thing with a 'linch-pin' that breaks the circle to allow reclamation of the objects
Either you deal with real bad, convoluted, hard to debug problems with a garbage collector for C++ or you deal with the simpler classical problem of freeing your objects when you are done with them.
Upvotes: 5
Reputation: 32986
Several C++ GC are listed on wikipedia.
However, I don't use any, RAII is also my friend.
Upvotes: 5
Reputation: 25724
The Boost library includes some shared_ptr stuff that basically acts as a reference counting garbage collector. If you embrace the RAII principle of C++ design, that and auto_ptr will fill your need for a "garbage collector".
Upvotes: 6
Reputation: 16581
The only one I've heard of personally is the Boehm garbage collector I'm sure others exist, but I've not dealt with them (or looked for them either).
Upvotes: 4