Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi,
i define uafxcwd.lib;LIBCMTD.lib in project settings, Additional dependency
my project is build in VS2010.

now i have problem to find memory leaks. because by adding this code:
#if defined(_DEBUG)
     #define _CRTDBG_MAP_ALLOC
     #include <stdlib.h>
     #include <crtdbg.h>
     #define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )
     #define new DEBUG_NEW
#endif


my project will be errors:
void* __cdecl operator new(unsigned int .... already defined in ...
void* __cdecl operator delete(void*.... already defined in ...
Posted
Comments
Sergey Alexandrovich Kryukov 24-Dec-13 3:14am    
How the compilation errors can be related to memory leaks? :-)
By the way, if you did not use any memory debugging, how do you know that you have a leak? If you, for example, just looked at Task Manager, you should not trust it.
—SA
[no name] 24-Dec-13 5:08am    
This comment bears no relation to the question. None of us can read minds. It is up to you to make the problem and the question clear to others.
Zon-cpp 24-Dec-13 5:41am    
visual studio 2010 report memory leak in output window like this: Detected memory leaks! Dumping objects -> {18} normal block at 0x00780E80, 64 bytes long. Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD But , it doesn't show name of the file and the line number where the leaked memory is first allocated.
Sergey Alexandrovich Kryukov 24-Dec-13 11:00am    
This is because there is no such point. If you allocate some memory, it may or may not be deallocated some time later, the point of allocation is not a point of a leak. And if deallocation is absent, this is the absence of some code fragment, not a point of a leak.

You need to use one of the memory debuggers, that's it.

—SA

Please see my comments to the question. Consider using one of the memory debuggers: http://en.wikipedia.org/wiki/Memory_debugger#List_of_memory_debugging_tools[^].

—SA
 
Share this answer
 
The code you add should be:

C++
#define _CRTDBG_MAP_ALLOC 
#include <stdlib.h>
#include <crtdbg.h>

#ifdef _DEBUG
   #ifndef DBG_NEW
      #define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
      #define new DBG_NEW
   #endif
#endif  // _DEBUG</crtdbg.h></stdlib.h>



Effective only in debug build.

http://msdn.microsoft.com/en-us/library/x98tx3cf(v=vs.100).aspx[^]

There are also comments at the bottom of this link page.
 
Share this answer
 
v2
Comments
Zon-cpp 24-Dec-13 5:48am    
But this code conflict with uafxcwd.lib (added in "Additional dependency")
Zon-cpp 25-Dec-13 4:59am    
my project is console and MFC then i don't use of #define DBG_NEW new

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900