What garbage collectors are available for C ++?

What garbage collectors are available for C ++? Do you use any of them? What are the results?

+6
c ++ garbage-collection
source share
6 answers

The Boost library includes some shared_ptr files, which basically act as a garbage collector for link counting. If you accept the RAII principle of a C ++ project, then auto_ptr will fill your need for a "garbage collector."

+6
source share

Several C ++ GCs are listed on wikipedia .

However, I do not use any, RAII is also my friend.

+5
source share

Boehm's garbage collector is good for C, but hard to use under C ++. Check out 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, select the language in which it is built.

The best general solution for C ++ is a generic pointer (e.g. from boost) when you are dealing with circular dependencies. There are two things you can do: 1. design a thing without circular dependencies 2. design an item using the "linch-pin" that breaks the circle to allow regeneration of objects

Either you are dealing with real bad, confusing, difficult to debug problems with the garbage collector for C ++, or you are dealing with a simpler classic problem of freeing your objects when you are done with them.

+5
source share

The only one I've heard about personally is the Boehm garbage collector. I'm sure others exist, but I didn't deal with them (or looked for them either).

+4
source share

Always, um: C ++ / CLI - C ++ for the .NET Framework. Pretty good garbage collection .: P

Although, to be honest, with all the syntactic sugar that they put there, you could almost consider it a completely new language that just works well with C / C ++.

If you are not married to C ++ as a language, you can also look at D , which compiles into native code, such as C ++ (and unlike C ++ / CLI), but also has garbage collection.

+2
source share

You can find several options here . I have never tried any of them, and in general I believe that a non-deterministic GC does more harm than good.

+2
source share

All Articles