• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1312
  • Last Modified:

VS2010 C++ Memory Leak detection software

I inherited a very large program, over 100K line, mixed with MFC C++ and native C codes. I am looking for a professional memory leak detection package. I just found the DevPartner and I am wondering is there anything better than that?  

My question is: "What is the best commercial memory leak detection software for the MFC C++ with VS2010?"   Cost is not an issue. I am looking for a package that can detect memory leak, both by scanning the code and reporting during the runtime.  It will be even better if it can suggest the code correction automatically.  

0
BaritoneH
Asked:
BaritoneH
  • 3
3 Solutions
 
phoffricCommented:
I used Parasoft C++ Insure++ program that literally savded a couple of projects. Given the quality of Ensure++, and their staying power in industry, I recommend them. And they will give you a free trial with technical support which will help you greatly.
    http://www.parasoft-embedded.com/products/insure.jsp
    http://www.parasoft.com/

Insure++ does much more than find memory leaks in real-time runs of your program.
    http://www.parasoft.com/jsp/products/slideshow/flash.jsp?popup=true&subdir=/products/support/presentation/flash/insure/Presentation7&ver=2&title=Insure

Parasoft also has an extensive automated Unit Test and System Regression Testing Suite which you may also be interested in if you are being saddled to maintain this 100K+ LOCs.
0
 
jkrCommented:
Forget about "code scanning" - if that would work, the compiler would already warn you. One simple yet cost-efficiant way (in terms of 'no costs') would be to add the following to a central header file:

#ifdef _DEBUG
#ifndef _DBG_NEW

#include <crtdbg.h>

inline void* __operator_new(size_t __n) {
     return ::operator new(__n,_NORMAL_BLOCK,__FILE__,__LINE__);
}
inline void* _cdecl operator new(size_t __n,const char* __fname,int __line) {
     return ::operator new(__n,_NORMAL_BLOCK,__fname,__line);
}
inline void _cdecl operator delete(void* __p,const char*,int) {
     ::operator delete(__p);
}

#define _DBG_NEW new(__FILE__,__LINE__)
#define new _DBG_NEW


#endif // _DBG_NEW
#else

#define __operator_new(__n) operator new(__n)

#endif

Then, add

               int tmpFlag;

               // Get the current state of the flag
               // and store it in a temporary variable
               tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );

               // Turn On (OR) - Keep freed memory blocks in the
               // heap’s linked list and mark them as freed
               tmpFlag |= _CRTDBG_LEAK_CHECK_DF;

               // Set the new state for the flag
               _CrtSetDbgFlag( tmpFlag );


to your app's start code and call

               _CrtDumpMemoryLeaks ();


to before the program ends and you'll get the line number where the allocation occured.

(Ref.: http:Q_21009673.html)

Ohm and yes - the results are comparable to what e.g. BoundsChecker would report.
0
 
phoffricCommented:
>> Forget about "code scanning" - if that would work, the compiler would already warn you.

If you are referring to the Insure++ product, then "code scanning" is the least important aspect. It is the dynamic run-time detection of memory issues that is of importance. You run the program, and it spits out memory issues.

BTW - I recall that the compilations with Insure++ did find many more problems than VC6.
0
 
trinitrotolueneCommented:
I would suggest you also give a try to Rational Purify

Purify

You can also evaluate PurifyPlus

0
 
phoffricCommented:
Yes, Purify. That is a competitor of Insure++. It went out of favor at my company in the early 90's when compared with Insure++; but since then, Purify was bought up by IBM, so perhaps, as part of the IBM "Rationale" line, it has improved.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now