Search code examples
c++memorymemory-managementraii

General guidelines to avoid memory leaks in C++


What are some general tips to make sure I don't leak memory in C++ programs? How do I figure out who should free memory that has been dynamically allocated?


Solution

  • Instead of managing memory manually, try to use smart pointers where applicable.
    Take a look at the Boost lib, TR1, and smart pointers.
    Also smart pointers are now a part of C++ standard called C++11.