How to check SDI app for memory leaks ?

How to check SDI app for memory leaks ?

Hi, experts!
I used to check my Dialog-based programs for memory leaks with simple way :

BOOL CMyApp::InitInstance()
{       // simplified version of InitInstance(), some things were cut

      CMemoryState st1, st2, diff;

      CMyDlg dlg;
      m_pMainWnd = &dlg;
      int nResponse = dlg.DoModal();

            TRACE("\n\n\n\n\nMemory OK\n\n\n\n\n");
            TRACE("\n\n\n\n\nMemory LEAK\n\n\n\n\n");

      return FALSE;

Question :

Is it possible to check for memory leaks SDI app.
If YES, where should I place CheckPoint()'s and Difference() calls ?
I want to see "Memory OK" for SDI-app created by wizard.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vinayak KumbarSr Program ManagerCommented:

Run the SDI app in the debug mode. I mean say F5 to the app to start debugging. Then do all the operations in Ur app. Then exit the app. The Vc++ will dump U the memory leaks if detected in the output window(it does for dialog based app also:-)). From that U can know the memory leaks. Else if U want it to be done using CheckPoint, then declare the class objects in the app.h file as
CMemoryState st1, st2, diff;

Then, in the initinstance take one snap shot. Then map the ExitInstance() for Ur app, there take one mpre snap shot of memory and find the difference.

There are many tools available to check for memory leaks also.

Try it out.
 Just furthering VinExperts's comment regarding the tools.
The most commonly used tools are
1. Bounds Checker
2. MemCheck.

Bounds checker is really very good and applies for all WIN32 applications.
Else you will have to do what VinExpert says.

INFO: Foundation Class Debug Library Detects Memory Leaks

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Unfortunately, BoundsChecker is well-known for singalling lots of false-positives.  Otherwise, it's a very valuable tool.

In the meantime, you can make your CMemoryState instances members of your CWinApp-derived class. Move your calls to Checkpoint() and Difference() to an override of ExitInstance().

This code (as well as the code you've presented) won't find all memory leaks, though--in particular, leaks caused by static objects won't be found.

..B ekiM
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.