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. Problem about finding memory leak

Problem about finding memory leak

Scheduled Pinned Locked Moved C / C++ / MFC
debugginghelpperformancequestion
4 Posts 3 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.
  • Y Offline
    Y Offline
    ytod
    wrote on last edited by
    #1

    While running debug mode on an application written by me, the debug would complain that it has memory leak:

    Detected memory leaks!
    Dumping objects ->
    {118957} normal block at 0x04D89230, 22960 bytes long.
    Data: < > 00 00 00 00 CD CD CD CD 00 00 00 00 00 00 00 00
    ...

    Is there any tool to trace the memory usage? It may be hard to find where the error is by simply trace the code( too long to examine X| ) Thanks!

    P F 2 Replies Last reply
    0
    • Y ytod

      While running debug mode on an application written by me, the debug would complain that it has memory leak:

      Detected memory leaks!
      Dumping objects ->
      {118957} normal block at 0x04D89230, 22960 bytes long.
      Data: < > 00 00 00 00 CD CD CD CD 00 00 00 00 00 00 00 00
      ...

      Is there any tool to trace the memory usage? It may be hard to find where the error is by simply trace the code( too long to examine X| ) Thanks!

      P Offline
      P Offline
      PJ Arends
      wrote on last edited by
      #2

      VS has the ability to help you with that. What you have to do is add the following lines, which should be there by default, to the beginning of every cpp file in your project

      #ifdef _DEBUG
      #define new DEBUG_NEW
      #undef THIS_FILE
      static char THIS_FILE[] = __FILE__;
      #endif

      If you have these lines in your code, then the debugger will give you the file name and line number of where the leaked memory was allocated, making it easier for you to figure out where you forgot to add the delete.


      "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

      Y 1 Reply Last reply
      0
      • P PJ Arends

        VS has the ability to help you with that. What you have to do is add the following lines, which should be there by default, to the beginning of every cpp file in your project

        #ifdef _DEBUG
        #define new DEBUG_NEW
        #undef THIS_FILE
        static char THIS_FILE[] = __FILE__;
        #endif

        If you have these lines in your code, then the debugger will give you the file name and line number of where the leaked memory was allocated, making it easier for you to figure out where you forgot to add the delete.


        "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

        Y Offline
        Y Offline
        ytod
        wrote on last edited by
        #3

        PJ Arends wrote: #undef THIS_FILE static char THIS_FILE[] = __FILE__; That's of great help, thanks!:-D

        1 Reply Last reply
        0
        • Y ytod

          While running debug mode on an application written by me, the debug would complain that it has memory leak:

          Detected memory leaks!
          Dumping objects ->
          {118957} normal block at 0x04D89230, 22960 bytes long.
          Data: < > 00 00 00 00 CD CD CD CD 00 00 00 00 00 00 00 00
          ...

          Is there any tool to trace the memory usage? It may be hard to find where the error is by simply trace the code( too long to examine X| ) Thanks!

          F Offline
          F Offline
          FayezElFar
          wrote on last edited by
          #4

          First you have to include the following files in your main .h file (so that you can have access to the following functions anywhere) //For debugging #define CRTDBG_MAP_ALLOC #include #include do them in this order. Now you can use the following function to actually call a memory dump with verbose leak pinpointing. _CrtDumpMemoryLeaks(); a small hint; bookmark the function, and clear your output window before stepping through the function call When the going gets tough... write a computer program to do the thing for you

          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