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. Identifying Memory leak location

Identifying Memory leak location

Scheduled Pinned Locked Moved C / C++ / MFC
questionperformance
7 Posts 6 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.
  • G Offline
    G Offline
    ganesh dp
    wrote on last edited by
    #1

    VC reporting some memory leaks in my application but without line number and file name. because of that i can't locate the leak. Report is given below

    Detected memory leaks!
    Dumping objects ->
    {159399} normal block at 0x04D98460, 1024 bytes long.
    Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
    {159398} normal block at 0x044E4F30, 36 bytes long.
    Data: <HG ` ` > 48 47 97 01 A2 CD CD CD 60 84 D9 04 60 84 D9 04
    {159397} normal block at 0x04D98028, 1024 bytes long.
    Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
    {159396} normal block at 0x04CABF20, 68 bytes long.
    Data: <(H ( ( > 28 48 97 01 A2 CD CD CD 28 80 D9 04 28 80 D9 04
    {159393} normal block at 0x044F37F0, 36 bytes long.
    Data: < 7O 8PN 7O > F0 37 4F 04 38 50 4E 04 F0 37 4F 04 CD CD CD CD
    {159392} normal block at 0x044E5038, 36 bytes long.
    {21242} normal block at 0x04507C18, 4 bytes long.
    The program 'D:\Kty\Program\kty.exe' has exited with code 0 (0x0).

    How can I locate leak?

    A N F C C 5 Replies Last reply
    0
    • G ganesh dp

      VC reporting some memory leaks in my application but without line number and file name. because of that i can't locate the leak. Report is given below

      Detected memory leaks!
      Dumping objects ->
      {159399} normal block at 0x04D98460, 1024 bytes long.
      Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
      {159398} normal block at 0x044E4F30, 36 bytes long.
      Data: <HG ` ` > 48 47 97 01 A2 CD CD CD 60 84 D9 04 60 84 D9 04
      {159397} normal block at 0x04D98028, 1024 bytes long.
      Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
      {159396} normal block at 0x04CABF20, 68 bytes long.
      Data: <(H ( ( > 28 48 97 01 A2 CD CD CD 28 80 D9 04 28 80 D9 04
      {159393} normal block at 0x044F37F0, 36 bytes long.
      Data: < 7O 8PN 7O > F0 37 4F 04 38 50 4E 04 F0 37 4F 04 CD CD CD CD
      {159392} normal block at 0x044E5038, 36 bytes long.
      {21242} normal block at 0x04507C18, 4 bytes long.
      The program 'D:\Kty\Program\kty.exe' has exited with code 0 (0x0).

      How can I locate leak?

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

      First thing to do is to avoid manually managing memory - then you won't have so many options for leaking memory. Replace raw pointers with decent smart pointers or just use automatic objects where you can. Secondly there are some biggish blocks in there. Have a look in you code for anywhere you use big buffers that you dynamically allocate. As the blocks are only 1k in size just throw them on the stack. After that if you're still having problems start thinking about using a diagnostic new and delete so you can start getting a handle on what you're allocating and not freeing. Cheers, Ash

      G 1 Reply Last reply
      0
      • A Aescleal

        First thing to do is to avoid manually managing memory - then you won't have so many options for leaking memory. Replace raw pointers with decent smart pointers or just use automatic objects where you can. Secondly there are some biggish blocks in there. Have a look in you code for anywhere you use big buffers that you dynamically allocate. As the blocks are only 1k in size just throw them on the stack. After that if you're still having problems start thinking about using a diagnostic new and delete so you can start getting a handle on what you're allocating and not freeing. Cheers, Ash

        G Offline
        G Offline
        ganesh dp
        wrote on last edited by
        #3

        thanks for reply. After that if you're still having problems start thinking about using a diagnostic new and delete so you can start getting a handle on what you're allocating and not freeing "diagnostic new and delete" - Can u explain it in detail

        1 Reply Last reply
        0
        • G ganesh dp

          VC reporting some memory leaks in my application but without line number and file name. because of that i can't locate the leak. Report is given below

          Detected memory leaks!
          Dumping objects ->
          {159399} normal block at 0x04D98460, 1024 bytes long.
          Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
          {159398} normal block at 0x044E4F30, 36 bytes long.
          Data: <HG ` ` > 48 47 97 01 A2 CD CD CD 60 84 D9 04 60 84 D9 04
          {159397} normal block at 0x04D98028, 1024 bytes long.
          Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
          {159396} normal block at 0x04CABF20, 68 bytes long.
          Data: <(H ( ( > 28 48 97 01 A2 CD CD CD 28 80 D9 04 28 80 D9 04
          {159393} normal block at 0x044F37F0, 36 bytes long.
          Data: < 7O 8PN 7O > F0 37 4F 04 38 50 4E 04 F0 37 4F 04 CD CD CD CD
          {159392} normal block at 0x044E5038, 36 bytes long.
          {21242} normal block at 0x04507C18, 4 bytes long.
          The program 'D:\Kty\Program\kty.exe' has exited with code 0 (0x0).

          How can I locate leak?

          N Offline
          N Offline
          Niklas L
          wrote on last edited by
          #4

          There are some other hints in there as well. The compiler makes sure allocated memory is filled with the value 0xCD for debug builds. That way the debugger can warn the user if you're trying to read uninitialized data. As you can see, both leaks of size 1024, seem to be unused. Also 1024 is a neat number, and I bet you could just search in your source code for '1024'. Someone is probably allocating a buffer they think is big enough for a task. You can also see the 'CD' pattern in the other dumps, indicating how the original layout might be. Assuming you have not altered the packing, it looks like the first 36 byte leak comes from a class or struct. The reason being the 3 CD in the middle. The struct might look something like

          struct (or class)
          {
          int n;
          char c;
          ...
          };

          where the n is 26691400 in this case. Does that number fit in somewhere? Like a database table index or similar? There are a lot of hints if you know how to read and interpret them.

          home

          1 Reply Last reply
          0
          • G ganesh dp

            VC reporting some memory leaks in my application but without line number and file name. because of that i can't locate the leak. Report is given below

            Detected memory leaks!
            Dumping objects ->
            {159399} normal block at 0x04D98460, 1024 bytes long.
            Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
            {159398} normal block at 0x044E4F30, 36 bytes long.
            Data: <HG ` ` > 48 47 97 01 A2 CD CD CD 60 84 D9 04 60 84 D9 04
            {159397} normal block at 0x04D98028, 1024 bytes long.
            Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
            {159396} normal block at 0x04CABF20, 68 bytes long.
            Data: <(H ( ( > 28 48 97 01 A2 CD CD CD 28 80 D9 04 28 80 D9 04
            {159393} normal block at 0x044F37F0, 36 bytes long.
            Data: < 7O 8PN 7O > F0 37 4F 04 38 50 4E 04 F0 37 4F 04 CD CD CD CD
            {159392} normal block at 0x044E5038, 36 bytes long.
            {21242} normal block at 0x04507C18, 4 bytes long.
            The program 'D:\Kty\Program\kty.exe' has exited with code 0 (0x0).

            How can I locate leak?

            F Offline
            F Offline
            Frank Seidler
            wrote on last edited by
            #5

            You can set a breakpoint when the memory is allocated. Take the number in curly braces and set it like this: _crtBreakAlloc = 159399; The debugger will break in, when the n-th memory block is allocated. see: http://msdn.microsoft.com/en-us/library/w2fhc9a3%28VS.80%29.aspx Regards Frank

            1 Reply Last reply
            0
            • G ganesh dp

              VC reporting some memory leaks in my application but without line number and file name. because of that i can't locate the leak. Report is given below

              Detected memory leaks!
              Dumping objects ->
              {159399} normal block at 0x04D98460, 1024 bytes long.
              Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
              {159398} normal block at 0x044E4F30, 36 bytes long.
              Data: <HG ` ` > 48 47 97 01 A2 CD CD CD 60 84 D9 04 60 84 D9 04
              {159397} normal block at 0x04D98028, 1024 bytes long.
              Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
              {159396} normal block at 0x04CABF20, 68 bytes long.
              Data: <(H ( ( > 28 48 97 01 A2 CD CD CD 28 80 D9 04 28 80 D9 04
              {159393} normal block at 0x044F37F0, 36 bytes long.
              Data: < 7O 8PN 7O > F0 37 4F 04 38 50 4E 04 F0 37 4F 04 CD CD CD CD
              {159392} normal block at 0x044E5038, 36 bytes long.
              {21242} normal block at 0x04507C18, 4 bytes long.
              The program 'D:\Kty\Program\kty.exe' has exited with code 0 (0x0).

              How can I locate leak?

              C Offline
              C Offline
              Chris Losinger
              wrote on last edited by
              #6

              see _crtBreakAlloc[^] basically, add this line to the very start of your program:

              _crtBreakAlloc(159399);

              then, when the CRT does its 159399th allocation, it will break (like an assert) and you can look at the stack to see who requested the allocation.

              image processing toolkits | batch image processing

              1 Reply Last reply
              0
              • G ganesh dp

                VC reporting some memory leaks in my application but without line number and file name. because of that i can't locate the leak. Report is given below

                Detected memory leaks!
                Dumping objects ->
                {159399} normal block at 0x04D98460, 1024 bytes long.
                Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
                {159398} normal block at 0x044E4F30, 36 bytes long.
                Data: <HG ` ` > 48 47 97 01 A2 CD CD CD 60 84 D9 04 60 84 D9 04
                {159397} normal block at 0x04D98028, 1024 bytes long.
                Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
                {159396} normal block at 0x04CABF20, 68 bytes long.
                Data: <(H ( ( > 28 48 97 01 A2 CD CD CD 28 80 D9 04 28 80 D9 04
                {159393} normal block at 0x044F37F0, 36 bytes long.
                Data: < 7O 8PN 7O > F0 37 4F 04 38 50 4E 04 F0 37 4F 04 CD CD CD CD
                {159392} normal block at 0x044E5038, 36 bytes long.
                {21242} normal block at 0x04507C18, 4 bytes long.
                The program 'D:\Kty\Program\kty.exe' has exited with code 0 (0x0).

                How can I locate leak?

                C Offline
                C Offline
                chen shi
                wrote on last edited by
                #7

                #define new DEBUG_NEW add this line to the beginning of source files witch you suspect leaking memory. then the report will have file name and line numbers. :) (sorry for my poor english.)

                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