Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. detecting memory leaks?

detecting memory leaks?

Scheduled Pinned Locked Moved C / C++ / MFC
performancetutorialquestioncode-review
12 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 9 Offline
    9 Offline
    9ine
    wrote on last edited by
    #1

    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

    A V P M 4 Replies Last reply
    0
    • 9 9ine

      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

      A Offline
      A Offline
      Axter
      wrote on last edited by
      #2

      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

      9 1 Reply Last reply
      0
      • 9 9ine

        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

        V Offline
        V Offline
        vipinasda
        wrote on last edited by
        #3

        Please have a look at umdh.exe Vipin - MVP

        A 1 Reply Last reply
        0
        • A Axter

          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

          9 Offline
          9 Offline
          9ine
          wrote on last edited by
          #4

          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

          A 1 Reply Last reply
          0
          • 9 9ine

            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

            A Offline
            A Offline
            Axter
            wrote on last edited by
            #5

            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

            9 1 Reply Last reply
            0
            • V vipinasda

              Please have a look at umdh.exe Vipin - MVP

              A Offline
              A Offline
              Axter
              wrote on last edited by
              #6

              What is umdh.exe? Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus

              V 1 Reply Last reply
              0
              • 9 9ine

                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

                P Offline
                P Offline
                Prakash Nadar
                wrote on last edited by
                #7

                Rational Purify?


                -Prakash

                1 Reply Last reply
                0
                • A Axter

                  What is umdh.exe? Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus

                  V Offline
                  V Offline
                  vipinasda
                  wrote on last edited by
                  #8

                  http://www.latenighthacking.com/archives/reference/Q268343%20-%20Umdhtools_exe%20How%20to%20Use%20Umdh_exe%20to%20Find%20Memory%20Leaks.html[^] Vipin - MVP

                  1 Reply Last reply
                  0
                  • 9 9ine

                    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

                    M Offline
                    M Offline
                    MF
                    wrote on last edited by
                    #9

                    In your application, (if it is a MFC application, add the following in the InitInstance()) _CrtSetBreakAlloc(715); it will break when it tries to allocation the leakage memory and you can find the source code. Details can be "Memory Leak Detection" in VS.

                    1 Reply Last reply
                    0
                    • A Axter

                      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

                      9 Offline
                      9 Offline
                      9ine
                      wrote on last edited by
                      #10

                      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

                      A 1 Reply Last reply
                      0
                      • 9 9ine

                        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

                        A Offline
                        A Offline
                        Axter
                        wrote on last edited by
                        #11

                        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

                        9 1 Reply Last reply
                        0
                        • A Axter

                          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

                          9 Offline
                          9 Offline
                          9ine
                          wrote on last edited by
                          #12

                          Thanks, great tool, now it works. 9ine

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups