detecting memory leaks?
-
I've got to improve some code with memory leaks but how to identify their location in a source file, I've got only this output after program terminates and not a hint for a source code: Detected memory leaks! Dumping objects -> {715} normal block at 0x00EAE450, 800 bytes long. Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD {541} normal block at 0x0033FBC8, 4 bytes long. Data: <0 > 30 00 00 00 {540} normal block at 0x0033FA10, 5 bytes long. Data: <000 > 30 30 30 00 CD {279} normal block at 0x0033F8A0, 8 bytes long. Data: < > 00 00 00 00 00 00 00 00 {273} normal block at 0x0033F6C0, 8 bytes long. Data: < > 16 1E 00 00 EA 1D 00 00 {272} normal block at 0x0033F680, 2 bytes long. Data: <01> 30 31 {268} normal block at 0x0033ED48, 4 bytes long. Data: < > 00 00 00 00 {266} normal block at 0x0033EE10, 2 bytes long. Data: <1 > 31 00 {264} normal block at 0x0033ED88, 2 bytes long. Data: <0 > 30 00 {232} normal block at 0x0033E3A0, 5 bytes long. Data: < > 00 00 00 00 00 Object dump complete. 9ine
I recommend you use the following FREE leak detecting code: http://code.axter.com/leaktracker.h[^] You can download the assoicated DLL file via following link: http://code.axter.com/leaktracker.zip[^] This program will output the leak location (source-file-name, line-number). It will also give the Function name if your compiler supports it (like VC++7.x & GNU 3.x) Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus -- modified at 8:28 Wednesday 28th December, 2005
-
I've got to improve some code with memory leaks but how to identify their location in a source file, I've got only this output after program terminates and not a hint for a source code: Detected memory leaks! Dumping objects -> {715} normal block at 0x00EAE450, 800 bytes long. Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD {541} normal block at 0x0033FBC8, 4 bytes long. Data: <0 > 30 00 00 00 {540} normal block at 0x0033FA10, 5 bytes long. Data: <000 > 30 30 30 00 CD {279} normal block at 0x0033F8A0, 8 bytes long. Data: < > 00 00 00 00 00 00 00 00 {273} normal block at 0x0033F6C0, 8 bytes long. Data: < > 16 1E 00 00 EA 1D 00 00 {272} normal block at 0x0033F680, 2 bytes long. Data: <01> 30 31 {268} normal block at 0x0033ED48, 4 bytes long. Data: < > 00 00 00 00 {266} normal block at 0x0033EE10, 2 bytes long. Data: <1 > 31 00 {264} normal block at 0x0033ED88, 2 bytes long. Data: <0 > 30 00 {232} normal block at 0x0033E3A0, 5 bytes long. Data: < > 00 00 00 00 00 Object dump complete. 9ine
-
I recommend you use the following FREE leak detecting code: http://code.axter.com/leaktracker.h[^] You can download the assoicated DLL file via following link: http://code.axter.com/leaktracker.zip[^] This program will output the leak location (source-file-name, line-number). It will also give the Function name if your compiler supports it (like VC++7.x & GNU 3.x) Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus -- modified at 8:28 Wednesday 28th December, 2005
this does not work, first I just added leaktracker.h to the project, lib and dll to windows system dir and run the project from VS 2003. Then closed the project and get standart memory leak in VS output window but there was no file C:\zz_David_Maisonave_DefaultLeakTrackerLogFile.log after termination. Then I added #include to the .cpp file that created additional mem leak on purpose for testing and the project doesnt want to be compiled: Compiling... sGenDlg.cpp ************************************************************************************** Note: Including leaktracker implementation... DO NOT USE THIS BUILD FOR PRODUCTION!!! ************************************************************************************** c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2433: 'new' : 'inline' not permitted on data declarations c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2365: 'new' : redefinition; previous definition was a 'member function' c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2078: too many initializers c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2440: 'initializing' : cannot convert from 'int' to 'void *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2143: syntax error : missing ';' before '(' c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2226: syntax error : unexpected type 'size_t' c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2059: syntax error : ')' c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2143: syntax error : missing ';' before '{' c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2447: '{' : missing function header (old-style formal list?) c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(188) : error C2433: 'new' : 'inline' not permitted on data declarations c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(188) : error C2365: 'new' : redefini
-
this does not work, first I just added leaktracker.h to the project, lib and dll to windows system dir and run the project from VS 2003. Then closed the project and get standart memory leak in VS output window but there was no file C:\zz_David_Maisonave_DefaultLeakTrackerLogFile.log after termination. Then I added #include to the .cpp file that created additional mem leak on purpose for testing and the project doesnt want to be compiled: Compiling... sGenDlg.cpp ************************************************************************************** Note: Including leaktracker implementation... DO NOT USE THIS BUILD FOR PRODUCTION!!! ************************************************************************************** c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2433: 'new' : 'inline' not permitted on data declarations c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2365: 'new' : redefinition; previous definition was a 'member function' c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2078: too many initializers c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2440: 'initializing' : cannot convert from 'int' to 'void *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2143: syntax error : missing ';' before '(' c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2226: syntax error : unexpected type 'size_t' c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2059: syntax error : ')' c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2143: syntax error : missing ';' before '{' c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2447: '{' : missing function header (old-style formal list?) c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(188) : error C2433: 'new' : 'inline' not permitted on data declarations c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(188) : error C2365: 'new' : redefini
In your sGenDlg.cpp file, the leaktracker.h must be the LAST included header. If you include it before any other headers, you'll get compile errors, or runtime errors. This program was originally developed using VS 2003, and then ported to GNU, Borland, and VC++ 6.0. So it should definitely work on VS 2003. FYI: If it doesn't produce a log file, then either it was not compiled in DEBUG moder, or there were no memory leaks. Since you didn't get compile errors the first time, I must assume it was not compiled in DEBUG mode. If you don't see the following message when you compile, then the leak tracking code is not getting included. ************************************************************************************** Note: Including leaktracker implementation... DO NOT USE THIS BUILD FOR PRODUCTION!!! ************************************************************************************** If you wish to include the leak tracking code in the release version of your program you could do so by defining the following macro before including the header: #define DEBUG_VERSION_ Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus -- modified at 10:59 Wednesday 28th December, 2005
-
What is umdh.exe? Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus
-
I've got to improve some code with memory leaks but how to identify their location in a source file, I've got only this output after program terminates and not a hint for a source code: Detected memory leaks! Dumping objects -> {715} normal block at 0x00EAE450, 800 bytes long. Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD {541} normal block at 0x0033FBC8, 4 bytes long. Data: <0 > 30 00 00 00 {540} normal block at 0x0033FA10, 5 bytes long. Data: <000 > 30 30 30 00 CD {279} normal block at 0x0033F8A0, 8 bytes long. Data: < > 00 00 00 00 00 00 00 00 {273} normal block at 0x0033F6C0, 8 bytes long. Data: < > 16 1E 00 00 EA 1D 00 00 {272} normal block at 0x0033F680, 2 bytes long. Data: <01> 30 31 {268} normal block at 0x0033ED48, 4 bytes long. Data: < > 00 00 00 00 {266} normal block at 0x0033EE10, 2 bytes long. Data: <1 > 31 00 {264} normal block at 0x0033ED88, 2 bytes long. Data: <0 > 30 00 {232} normal block at 0x0033E3A0, 5 bytes long. Data: < > 00 00 00 00 00 Object dump complete. 9ine
Rational Purify?
-Prakash
-
What is umdh.exe? Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus
-
I've got to improve some code with memory leaks but how to identify their location in a source file, I've got only this output after program terminates and not a hint for a source code: Detected memory leaks! Dumping objects -> {715} normal block at 0x00EAE450, 800 bytes long. Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD {541} normal block at 0x0033FBC8, 4 bytes long. Data: <0 > 30 00 00 00 {540} normal block at 0x0033FA10, 5 bytes long. Data: <000 > 30 30 30 00 CD {279} normal block at 0x0033F8A0, 8 bytes long. Data: < > 00 00 00 00 00 00 00 00 {273} normal block at 0x0033F6C0, 8 bytes long. Data: < > 16 1E 00 00 EA 1D 00 00 {272} normal block at 0x0033F680, 2 bytes long. Data: <01> 30 31 {268} normal block at 0x0033ED48, 4 bytes long. Data: < > 00 00 00 00 {266} normal block at 0x0033EE10, 2 bytes long. Data: <1 > 31 00 {264} normal block at 0x0033ED88, 2 bytes long. Data: <0 > 30 00 {232} normal block at 0x0033E3A0, 5 bytes long. Data: < > 00 00 00 00 00 Object dump complete. 9ine
-
In your sGenDlg.cpp file, the leaktracker.h must be the LAST included header. If you include it before any other headers, you'll get compile errors, or runtime errors. This program was originally developed using VS 2003, and then ported to GNU, Borland, and VC++ 6.0. So it should definitely work on VS 2003. FYI: If it doesn't produce a log file, then either it was not compiled in DEBUG moder, or there were no memory leaks. Since you didn't get compile errors the first time, I must assume it was not compiled in DEBUG mode. If you don't see the following message when you compile, then the leak tracking code is not getting included. ************************************************************************************** Note: Including leaktracker implementation... DO NOT USE THIS BUILD FOR PRODUCTION!!! ************************************************************************************** If you wish to include the leak tracking code in the release version of your program you could do so by defining the following macro before including the header: #define DEBUG_VERSION_ Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus -- modified at 10:59 Wednesday 28th December, 2005
No I'm not inclined to use it in release version, I'm sure I've got debug compiler option and I included it as you said: #include "stdafx.h" #include "sGen.h" #include "sGenDlg.h" #include ".\sgendlg.h" #ifdef _DEBUG #define new DEBUG_NEW #endif #include "Lib\lib.h" #include "Lib\quantize.h" #include "LibST\scomplexity.h" // CsGenDlg dialog #include "leaktracker.h" CsGenDlg::CsGenDlg(CWnd* pParent /*=NULL*/) : CDialog(CsGenDlg::IDD, pParent) , m_freq(10) , m_sr(128) , m_len(30), data(0) , m_asize(2) , qt(0) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } All the same compiler errors again? it doesnt want to be compiled, I use VS2003. As for the first time I did not include leaktracker.h in any cpp file at all, which is not proper as I've read from its manual that it should be included at least in one file, and I ran it in debug mode (which we select from proj settings->config manager->active solution config), and to test it I used on purpose allocation of memory with new command without deleting it. What is your suggestions? look at the errors again: Compiling... sGenDlg.cpp ************************************************************************************** Note: Including leaktracker implementation... DO NOT USE THIS BUILD FOR PRODUCTION!!! ************************************************************************************** c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2433: 'new' : 'inline' not permitted on data declarations c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2365: 'new' : redefinition; previous definition was a 'member function' c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2078: too many initializers c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2440: 'initializing' : cannot convert from 'int' to 'void *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2143: syntax error : missing ';' before '(' c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2226: syntax error : unexpected type 'size_t' c:\Documents and Settings\yc274\My Documents\Visual Studio Projects
-
No I'm not inclined to use it in release version, I'm sure I've got debug compiler option and I included it as you said: #include "stdafx.h" #include "sGen.h" #include "sGenDlg.h" #include ".\sgendlg.h" #ifdef _DEBUG #define new DEBUG_NEW #endif #include "Lib\lib.h" #include "Lib\quantize.h" #include "LibST\scomplexity.h" // CsGenDlg dialog #include "leaktracker.h" CsGenDlg::CsGenDlg(CWnd* pParent /*=NULL*/) : CDialog(CsGenDlg::IDD, pParent) , m_freq(10) , m_sr(128) , m_len(30), data(0) , m_asize(2) , qt(0) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } All the same compiler errors again? it doesnt want to be compiled, I use VS2003. As for the first time I did not include leaktracker.h in any cpp file at all, which is not proper as I've read from its manual that it should be included at least in one file, and I ran it in debug mode (which we select from proj settings->config manager->active solution config), and to test it I used on purpose allocation of memory with new command without deleting it. What is your suggestions? look at the errors again: Compiling... sGenDlg.cpp ************************************************************************************** Note: Including leaktracker implementation... DO NOT USE THIS BUILD FOR PRODUCTION!!! ************************************************************************************** c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2433: 'new' : 'inline' not permitted on data declarations c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2365: 'new' : redefinition; previous definition was a 'member function' c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2078: too many initializers c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2440: 'initializing' : cannot convert from 'int' to 'void *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2143: syntax error : missing ';' before '(' c:\Documents and Settings\yc274\My Documents\Visual Studio Projects\COMPL\sGen\leaktracker.h(184) : error C2226: syntax error : unexpected type 'size_t' c:\Documents and Settings\yc274\My Documents\Visual Studio Projects
I see the problem. This is an over-sight on our part. In your above code, you have the following: #ifdef _DEBUG #define new DEBUG_NEW #endif If you include the leaktracker.h file after the above line, that will cause the compile errors. I've updated the leaktracker.h file so that it does an #undef for new. #ifdef new #undef new #endif //new You can download the new version, or just add the above 3 lines in the leaktracker.h file around line 177 (right before the new operator). http://code.axter.com/leaktracker.h[^] FYI: If you're using MFC, also make sure to include the header after macros like IMPLEMENT_DYNCREATE. Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus
-
I see the problem. This is an over-sight on our part. In your above code, you have the following: #ifdef _DEBUG #define new DEBUG_NEW #endif If you include the leaktracker.h file after the above line, that will cause the compile errors. I've updated the leaktracker.h file so that it does an #undef for new. #ifdef new #undef new #endif //new You can download the new version, or just add the above 3 lines in the leaktracker.h file around line 177 (right before the new operator). http://code.axter.com/leaktracker.h[^] FYI: If you're using MFC, also make sure to include the header after macros like IMPLEMENT_DYNCREATE. Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus