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

how to repaint when working with horizontal scroll bar

0 Answers  


what is the difference between compiling and building?

1 Answers  


What MFC base classes provide support for ActiveX controls?

2 Answers   Wipro,


if i modified data in 1 view how does the other view knows

2 Answers   Siemens,


What view class enables you to use an edit control as a view?

1 Answers  






What is the difference between OnInitialUpdate and OnUpdate?

5 Answers  


plzz tell me what we can do and dont in tally ERP & sap business one?

0 Answers  


Whats is DDX & DDV in MFC?

1 Answers   HCL,


I want recent paper pattern for HP company?

0 Answers   HP,


How to setup a timer?

3 Answers   IBM,


What is the initial function to be called in MFC and what it will do

11 Answers   Infosys,


What is difference between the TCP/IP and UDP socket

5 Answers   Invensys,


Categories