Garbage Collector for C ++

5

I clearly understand what a Garbage Collector is and what a Garbage Collector is for. It is very well known in Java.

Is there a library in C ++ that implements GC or fixes memory lLeaks?

I have already searched the internet but it always results in C ++ for Visual Studio, which is not useful.

    
asked by anonymous 14.12.2015 / 18:28

1 answer

5

There is Microsoft's C ++ / CLI . It is not the default C ++, but I use the same GC in C #.

Some people find that proper use of smart pointers is still a one-way of GC. Others find that not quite the case, although both manage memory automatically. It is understandable that this form is a little more limited, but works very well if you know what you are doing.

In addition, libraries can be used to help with this. The newer versions of the standard C ++ have been specifying ways to facilitate the development of more complex GCs for optional use, but as far as I know, there is nothing too good to use yet. Today it is not easy to do a GC for C ++. Language does not help.

There are conservative GCs that help, but cause so much leakage that they become unworkable in most cases. The most well known is the Boehm .

If you do not know what you are doing, even with GC, there is memory leak. In any language. You have no idea how many applications have leaks and no one notices. It is usually noticeable only when the leak is very serious (common in C / C ++) and when the application runs for a long time, which is uncommon in cases of other languages.

If you really think GC can help a lot, consider using a different language.

    
14.12.2015 / 18:46