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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
How can I test my application for memory leaks.I use Dev-c++ 4.9.9.2
Thanks for the reply.
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