 |
|
|
 |
|
 |
No, Java uses a totally different technique for memory deallocation. My code doesn't apply.
Java uses a garbage collector, i suggest you read up on that. Basics: Don't create circular reference chains and only use finalize methods to deallocate stuff. And as always... Don't allocate if you can reuse.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
It works great with Visual Studio 6 C++ using multithreaded DLL linking as long as you do NOT select the "Ignore all default libraries" option under the link tab (general). If you do it won't be able to resolve linkage to dbghelp.dll in the windows directory and you'll get messages like:
error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::ios_base::Init::Init(void)" (__imp_??0Init@ios_base@std@@QAE@XZ) error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::ios_base::Init::~Init(void)" (__imp_??1Init@ios_base@std@@QAE@XZ) error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Winit::_Winit(void)" (__imp_??0_Winit@std@@QAE@XZ) error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Winit::~_Winit(void)" (__imp_??1_Winit@std@@QAE@XZ) error LNK2001: unresolved external symbol __imp__SymCleanup@4 error LNK2001: unresolved external symbol __imp__SymInitialize@12 error LNK2001: unresolved external symbol __imp__SymSetOptions@4 error LNK2001: unresolved external symbol __imp__SymGetOptions@0 error LNK2001: unresolved external symbol __imp__SymGetModuleInfo@12 error LNK2001: unresolved external symbol __imp__UnDecorateSymbolName@16 error LNK2001: unresolved external symbol __imp__SymGetSymFromAddr@16 error LNK2001: unresolved external symbol __imp__SymGetLineFromAddr@16 error LNK2001: unresolved external symbol __imp__StackWalk@36 error LNK2001: unresolved external symbol __imp__SymFunctionTableAccess@8 error LNK2001: unresolved external symbol __imp__SymGetModuleBase@8
Jay
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Huh, where is it? Unfortunately, the code I downloaded has no date information, but the files are from 2003 and 2004...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Only the dll version of the source is upgraded to latest code. The dll version can however be used for all projects and it is a simple task to modify it if a monolithic executable is needed.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I got 9 linker errors. The first one is: nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int,char const *,int)" (??2@YAPAXIPBDH@Z) already defined in tracealloc.obj
Can someone help me?
I'm using VC.NET 2002 with SP1, added tracealloc.cpp only to my project and recompiled. I also added to ignore nafxcwd.lib in Ignore specific library in the Linker
Thanks Garrison
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,Thanks I got this error too. I create a project with VS 2008 , MFC shared dll , unicode. How tell linker that i use the source code function ,replace the dll function?
1>Linking... 1>tracealloc.obj : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in mfc90ud.lib(mfc90ud.dll) 1>tracealloc.obj : error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) already defined in msvcrtd.lib(MSVCR90D.dll) 1>Build log was saved 1>operator_new_overload_test_mfc - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
You need to force the compiler to accept multiple declarations of a function by setting an argument to the linker as: /FORCE:MULTIPLE. This will make the compiler ignore all subsequent declarations of a function. Just make sure that the linker finds the tracealloc versions of new and delete first.
The instructions for this scenario is described in the sourcecode.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
I am using VC8 and am getting some errors during compile.
memleakfinder\tracealloc.cpp(246) : error C2440: '=' : cannot convert from 'const char *' to 'LPTSTR'
This is also errored on line 258 as well as 246. Any suggestions?
Also, there is an undefined 'i' error at line 547 because of the new scope requirements.
I fixed it with a define at line 545 with a "size_t i;" and removed the define in the for loop:
bool AssertMem(char* m, char c, size_t s) { size_t i; for (i = 0; i < s; i++) if (m[i] != c) break; return i >= s; }
I await your response to the first problem, please...
Regards, David Leikis
|
| Sign In·View Thread·PermaLink | 4.20/5 (2 votes) |
|
|
|
 |
|
 |
I fixed the compile errors, but wanted you to know all of the details...
I fixed the LPTSTR error simply by casting the return to:
lpszParamSep = (LPTSTR)_tcschr( lpszParsed, _T(',') );
I hope that this helps.
I will now be trying to use your code. Thank you for your efforts! I hope this helps me find my leaks.
David Leikis
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi
Can you guide me through the step by step procedure of tracking the memory leak....
I am not able to get how to get the memory leak tool to work for working
Can you help me out...
Thanks and Regards Chandrasekar
Chandrasekar
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
If you compile a DLL with the __stdcall calling convention, don't forget to add the __cdecl to the new and delete declarations.
I got this on my debug output:
Memory statistics ----------------- Total allocations: 500 Max concurrent allocations: 43
Does this means I have no leaks?
Thanks for sharing this tool!
Regards, João Paulo Figueira Embedded MVP
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I've solved your problem with detect leaks in dll. At first, you should add this code .... HANDLE g_hSymInitProcess = NULL; .... Then in InitSymInfo tou should add DWORD dwProcessID = GetCurrentProcessId(); g_hSymInitProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessID);
BOOL Res = SymInitialize( g_hSymInitProcess, lpszSymbolPath, TRUE); You cannot use GetCurrentProcess() (see MSDN for SymInitialize) And then replace all GetCurrentProcess() with g_hSymInitProcess In ~cLeakDetector() add CloseHandle(g_hSymInitProcess) After that you should compile dll without exporting any additional functions. And it will detect all memory leak in dll. The same is in execitable.
And I want you to write about how to install debuging tools. I met with this problem and some interesting things. After install debuging tools there is the old version of dll in WinDir\System32. The same after manualy replace dll. So I found that Windows replace dbhhelp.dll if it find that this dll is not native (same for all system dll). So that you should firstly replace dbghelp.dll in dllcache folder and after that in system32 follder.
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
 |
When using the sample project to test the memory leak detector I get no line numbers/file details.
I did some hacking around with tracealloc.cpp. The call stacks its getting in GetStackTrace don't seem to be what I want. The only element in them is always:
ntdll!0x7C90EB94 : KiFastSystemCallRet
Any thoughts?
-Andrew
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
if you change the new operator like this
void* operator new(size_t s) { UINT e = GetLastError(); void *r = TraceAlloc(s); UINT e1 = GetLastError(); return r; }
e will be 0 in my code, but e1 will be 487. It would not affect anything in my programm, but I find it confusing. Took some time to find out, that windows sets this error inside the new operator instead of my own code.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
The TraceAlloc function uses functions from windows that can set raise an error. The errorvalue 487 means: Attempt to access invalid address, ERROR_INVALID_ADDRESS
This is a standard memory accessvoliation but why you get this error I do not know. You'll have to debug to find out where and when this error occurs.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
following is the code void generate_memoryleak(){ new int; // Generate a memory leak } int main(int argc, char** argv){ generate_memoryleak(); return 0; }
but i got the result as Leak of 4 bytes detected: main!0x004012FF : ? main!0x0040134D : ? main!0x004081E9 : ? kernel32!0x77E814C7 : GetCurrentDirectoryW
please help me TIA Binu Jose
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
I am using VC6 with _UNICODE directive. tracealloc.cpp is not compiling because is using macros like va_list that are based on char *.
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
I don't have access to VC6 anymore but the sample solution above works with UNICODE on VC.NET.
What compiler errors do you get?
|
| Sign In·View Thread·PermaLink | 3.67/5 (2 votes) |
|
|
|
 |
|
 |
Those are soe of the errors I am getting:
Compiling... tracealloc.cpp D:\temp\MemLeakFinder\tracealloc.cpp(72) : error C2664: 'vswprintf' : cannot convert parameter 1 from 'char [4096]' to 'unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast D:\temp\MemLeakFinder\tracealloc.cpp(182) : error C2664: 'wcscpy' : cannot convert parameter 1 from 'char *' to 'unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast D:\temp\MemLeakFinder\tracealloc.cpp(193) : error C2440: 'initializing' : cannot convert from 'unsigned short [2]' to 'char [4096]' There is no context in which this conversion is possible
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |