Menu

testing for leaks

Bond Serj
2009-02-18
2012-09-26
  • Bond Serj

    Bond Serj - 2009-02-18

    How can I test my application for memory leaks.I use Dev-c++ 4.9.9.2

     
    • Bond Serj

      Bond Serj - 2009-02-20

      Thanks for the reply.

       
    • cpns

      cpns - 2009-02-19

      Port it to Linux and use Valgrind. That is honestly it, similar tools on Windows typically cost money.

      If you use VC++ 2008 (the Express Edition is free), and run the code in the debugger, then on exit on termination of the process, the IDE will report memory leaks, but may not provide sufficient information for you to locate the problem.

      The best approach is to adopt practices that help avoid such problems. In C++ keeping allocation/deallocation within paired constructors/destructors is one. Using STL container classes is another, since these perform memory management for you as does std::string. Personally, when i write a dynamic allocation, I write its deallocation at the same time, there and then. So say, if is instantiate a new object in a constructor, I add its deletion to the corresponding destructor straight away.

      It is worth monitoring your process in Windows Task Manager, to observe its memory usage over time to determine if it is as expected. There is usually little harm in an application allocating a block and not returning it to the heap before termination, the heap belongs to the process, and the OS recovers it all on termination in any case. Leaks become a problem however if you iteratively allocate memory and never release it, and that loop runs indefinitely, eventually starving your system of memory resources for other processes.

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.