How you find memory leaks?

Answers were Sorted based on User's Feedback



How you find memory leaks?..

Answer / jawahar

There many ways to find memory leaks, One of the ways is by
using MFC class. And another way is using Purify tools...

CMemorState is a MFC class by which we can find the memory
leaks. Below is a sample code to find the same.

#ifdef _DEBUG
CMemoryState oldState, newState, diffState;
oldState.Checkpoint();
#endif
int* a = new int[10];
#ifdef _DEBUG
newState.Checkpoint();
if(diffState.Difference(oldState, newState))
{
TRACE0("Memory Leaked");
}
#endif

Is This Answer Correct ?    8 Yes 0 No

How you find memory leaks?..

Answer / umesh pai

There is a pretty easiest way to identify whether ur application is having any memory leak. By using the macro called DEBUG_NEW

define this macro on each of urs cpp file.
like #define DEBUG_NEW

then if u run once ur application in debug mode, it will show each variable which has not been released the memory properly.

Is This Answer Correct ?    8 Yes 3 No

How you find memory leaks?..

Answer / gopal sodhani

macro should be
#define new DEBUG_NEW, in such case once you insert this
directive, the preprocessor will insert DEBUG_NEW wherever
you use new, and MFC does the rest.

Is This Answer Correct ?    4 Yes 0 No

How you find memory leaks?..

Answer / nibha

there are various tool like UMDH,DevPartner, through which
can get line number and function name where memory is
leaking

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More MFC Interview Questions

Tell us something about MFC?

7 Answers   Microsoft,


Tell me the different controls in MFC ?

5 Answers  


1)how to Display the File Dialog Box, in MFC ?

1 Answers  


is there any class which is not derived from Cobject

11 Answers   Patni,


What is the base class for MFC Framework ?

2 Answers   Mphasis,






what is the use of Mutex and critical section

2 Answers  


what if we provide two message handler for same message ?

1 Answers  


Name the Synchronization objects?

2 Answers  


How do I create a dialog box in mfc?

0 Answers  


Hi All, I have created one MFC Dialog Based application.now if i am running the application its working fine,instead of closing he application i minimized the application,if i run the application again,i am getting the Dialog. I want to prevent the calling of application multiple times. please give me the code and let me know in which method i need to make changes. Praveer

7 Answers   HP,


What is the use of CCmdTarget ?

4 Answers  


How to update windows title bar dynamically?

7 Answers   HCL,


Categories