How will you detect if there is memory leak in your C++ program?

How will you detect if there is memory leak in your C++ program?

Some time before we have got a some problem of detecting memory leaks in our code, and we didn't afforrd the rates of a brittle software package to do that. It's fairly simple to redefine malloc() and free() to your own functions, to track the file and line number of memory leaks. But what about the new() and delete() operators? It's a little more difficult with C++, if we want to figure out the exact line number of a resource leak.
   If we are using new and delete operator, We can overload both the operators and can count number off heap allocation and deallocation. You can also get the __FILE__ and __LINE__ to get to know the file name and line number. Now the new and delete of a memory location should be in pair and if its not there is a memroy leak. By using line and file utility you can reach upto the exact location.

By:UMANG
Date:2001-01-09 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related C Subjective Links

C Subjective interview questions and answers for experienced and fresher