2

Visual Studio 2010 に統合できるメモリ リークの良いプラグインを教えてもらえますか? どんなアドバイスでもいいです。

4

3 に答える 3

5

VisualLeakDetectorを使用してみてください。ただし、これはVisualC++を対象としています。

于 2012-06-21T12:29:50.863 に答える
1

次のことができます。

#ifdef _DEBUG
# define _CRTDBG_MAP_ALLOC 1 // better in project file in DEBUG mode
# include <crtdbg.h>
# include <new>
# define malloc(size)       _malloc_dbg(size,_CLIENT_BLOCK,__FILE__,__LINE__)
# define realloc(addr,size) _realloc_dbg(addr,size,_CLIENT_BLOCK,__FILE__,__LINE__)
# define free(addr)         _free_dbg(addr,_CLIENT_BLOCK)

void * __stdcall operator new ( size_t size, const char * filename, int linenumber )
{
  void * tmp = _malloc_dbg( size, _CLIENT_BLOCK, filename, linenumber );
  if ( tmp == NULL )
    throw std::bad_alloc;
  return tmp;
}
void * __stdcall operator new [] ( size_t size, const char * filename, int linenumber )
{
  void * tmp = _malloc_dbg( size, _CLIENT_BLOCK, filename, linenumber );
  if ( tmp == NULL )
    throw std::bad_alloc;
  return tmp;
}
// If you need, you could implement the nothrow version of new operator, too.
void __stdcall operator delete( void *p, const char * filename, int linenumber )
{
  _free_dbg(p,_CLIENT_BLOCK)
}
void __stdcall operator delete[]( void *p, const char * filename, int linenumber )
{
  _free_dbg(p,_CLIENT_BLOCK)
}
void __stdcall operator delete( void *p )
{
  _free_dbg(p,_CLIENT_BLOCK)
}
void __stdcall operator delete[]( void *p )
{
  _free_dbg(p,_CLIENT_BLOCK)
}
// if there is MFC, you could use MFC style DEBUG_NEW
# ifdef DEBUG_NEW
#  define new DEBUG_NEW
# else
#  define DEBUG_NEW_HEAP new( __FILE__, __LINE__ )
#  define new DEBUG_NEW_HEAP
# endif
#endif

このように、プロファイラーや追加のプラグインは必要ありません。Visual Studio が自動的にメモリ リークを収集します (Professional バージョンで十分です)。

于 2012-06-21T13:39:50.417 に答える
1

Visual studio と統合できるBoundsCheckerを試すことができます!

于 2012-06-21T12:39:04.203 に答える