How you find memory leaks?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
Why not virtual functions to handle messages?
if no message handler is available for a message then will deal with the message ? does window proving any default mechanism?
Do you have an idea about MFC?
Explain in sort What is CTargetObject?
What is a message map, and what is the advantage of a message map over virtual functions?
1) Enable or disable a Cancel button at run time?
What are the advantages of using Doc/View or SDI over DialogBox
Whats is DDX & DDV in MFC?
how u can move CDC pointer to one line in cview?
What is the difference between Extension DLL and Regular DLL?
WHAT IS DIFFERENT BETWEN RELEASE MODE & DEBUGGING MODE
4 Answers Google, Microsoft, TCS,
What are the differences between MFC Exception macros and C++ exception keywords?