Garbage Collection

I've taken Java classes in school, and I know that it has a built in garbage collector, but I have been teaching myself about C++, and I don't have a clue about garbage collecting, and I'm sure that all of my C++ programs have memory leaks. What tutorials do a good job explaining how to garbage collect starting at a very basic level and continuing to a more advanced level?
C/C++ has no garbage collector. You shall yourself free unused heap memory.
In C++, the best ways to avoid memory leaks are:

1) Don't use new unless you have to
2) Use containers like vector rather than trying to allocate memory yourself
3) if you have to use new, put it in a smart pointer (like unique_ptr) so you do not have to manually delete it.
4) If you are using a C lib that expects you to clean up (for example, creating GDI objects in Windows), write classes which exercise RAII and destroy their objects in the destructor.
Topic archived. No new replies allowed.