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

Memory leak

Scheduled Pinned Locked Moved C / C++ / MFC
questionperformance
9 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.
  • J Offline
    J Offline
    Janine
    wrote on last edited by
    #1

    Hello, I apologise, if this question has been asked before. I couldn't check it because the search doesn't work. There's a memory leak in my program. The part of the memory that leaks is allocated (at least) during call ProcessShellCommand(cmdInfo) and it is allocated by function CString::AllocBuffer(by line new BYTE[sizeof(CStringData) + (nLen+1)*sizeof(TCHAR)];). Is there anything I can do about this memory leak?:confused: I mean because I don't directly call AllocBuffer myself, can I do anything about it? BTW the start point of my program is main and I call InitInstance() and Run() from there, if it has something to do with this. -Janetta

    T S 2 Replies Last reply
    0
    • J Janine

      Hello, I apologise, if this question has been asked before. I couldn't check it because the search doesn't work. There's a memory leak in my program. The part of the memory that leaks is allocated (at least) during call ProcessShellCommand(cmdInfo) and it is allocated by function CString::AllocBuffer(by line new BYTE[sizeof(CStringData) + (nLen+1)*sizeof(TCHAR)];). Is there anything I can do about this memory leak?:confused: I mean because I don't directly call AllocBuffer myself, can I do anything about it? BTW the start point of my program is main and I call InitInstance() and Run() from there, if it has something to do with this. -Janetta

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      Why did you use your own 'main'? Tomasz Sowinski -- http://www.shooltz.com

      Never argue with an idiot, he'll bring you to his level and beat you with experience.

      J 1 Reply Last reply
      0
      • T Tomasz Sowinski

        Why did you use your own 'main'? Tomasz Sowinski -- http://www.shooltz.com

        Never argue with an idiot, he'll bring you to his level and beat you with experience.

        J Offline
        J Offline
        Janine
        wrote on last edited by
        #3

        Tomasz Sowinski wrote: Why did you use your own 'main'? It has to work as a console application in windows and unix besides gui. -Janetta

        T 1 Reply Last reply
        0
        • J Janine

          Tomasz Sowinski wrote: Why did you use your own 'main'? It has to work as a console application in windows and unix besides gui. -Janetta

          T Offline
          T Offline
          Tomasz Sowinski
          wrote on last edited by
          #4

          But you've copied the AfxWinMain into your main, including the calls to AfxWinTerm? Tomasz Sowinski -- http://www.shooltz.com

          Never argue with an idiot, he'll bring you to his level and beat you with experience.

          J 1 Reply Last reply
          0
          • T Tomasz Sowinski

            But you've copied the AfxWinMain into your main, including the calls to AfxWinTerm? Tomasz Sowinski -- http://www.shooltz.com

            Never argue with an idiot, he'll bring you to his level and beat you with experience.

            J Offline
            J Offline
            Janine
            wrote on last edited by
            #5

            Tomasz Sowinski wrote: But you've copied the AfxWinMain into your main, including the calls to AfxWinTerm? No. I call AfxWinInit, InitApplication, InitInstance and Run myself. In AfxWinMain InitInstance and Run are called to a CWinThread, but I call those of the application. Could this be the problem? I tried adding AfxWinTerm after Run, but it didn't help. -Janetta

            T 1 Reply Last reply
            0
            • J Janine

              Tomasz Sowinski wrote: But you've copied the AfxWinMain into your main, including the calls to AfxWinTerm? No. I call AfxWinInit, InitApplication, InitInstance and Run myself. In AfxWinMain InitInstance and Run are called to a CWinThread, but I call those of the application. Could this be the problem? I tried adding AfxWinTerm after Run, but it didn't help. -Janetta

              T Offline
              T Offline
              Tomasz Sowinski
              wrote on last edited by
              #6

              Janetta wrote: call those of the application. Could this be the problem? I don't think so, but you may try to copy AfxWinMain into your main. Tomasz Sowinski -- http://www.shooltz.com

              Never argue with an idiot, he'll bring you to his level and beat you with experience.

              J 1 Reply Last reply
              0
              • T Tomasz Sowinski

                Janetta wrote: call those of the application. Could this be the problem? I don't think so, but you may try to copy AfxWinMain into your main. Tomasz Sowinski -- http://www.shooltz.com

                Never argue with an idiot, he'll bring you to his level and beat you with experience.

                J Offline
                J Offline
                Janine
                wrote on last edited by
                #7

                Tried already, didn't help. Thank you anyway! Anyone got any other ideas? Can I rely on CStrings being safe and not leaking memory themselves? -Janetta

                1 Reply Last reply
                0
                • J Janine

                  Hello, I apologise, if this question has been asked before. I couldn't check it because the search doesn't work. There's a memory leak in my program. The part of the memory that leaks is allocated (at least) during call ProcessShellCommand(cmdInfo) and it is allocated by function CString::AllocBuffer(by line new BYTE[sizeof(CStringData) + (nLen+1)*sizeof(TCHAR)];). Is there anything I can do about this memory leak?:confused: I mean because I don't directly call AllocBuffer myself, can I do anything about it? BTW the start point of my program is main and I call InitInstance() and Run() from there, if it has something to do with this. -Janetta

                  S Offline
                  S Offline
                  Steen Krogsgaard
                  wrote on last edited by
                  #8

                  The CString data should delete itself when the ref count goes to zero. Which CString instance leaks? Do you do any CString::LockBuffer/CString::GetBuffer calls without matching CString::UnlockBuffer/CString::ReleaseBuffer? Another possibility is that it doesn't really leak, I've seen people here at CP complaining that their leak detector was wrong (was it BoundChecker? Purify? I can't remember, doesn't use one myself), especially when dealing with global objects (such as the global CWinApp instance). Cheers Steen. "To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"

                  J 1 Reply Last reply
                  0
                  • S Steen Krogsgaard

                    The CString data should delete itself when the ref count goes to zero. Which CString instance leaks? Do you do any CString::LockBuffer/CString::GetBuffer calls without matching CString::UnlockBuffer/CString::ReleaseBuffer? Another possibility is that it doesn't really leak, I've seen people here at CP complaining that their leak detector was wrong (was it BoundChecker? Purify? I can't remember, doesn't use one myself), especially when dealing with global objects (such as the global CWinApp instance). Cheers Steen. "To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"

                    J Offline
                    J Offline
                    Janine
                    wrote on last edited by
                    #9

                    Steen Krogsgaard wrote: Do you do any CString::LockBuffer/CString::GetBuffer calls without matching CString::UnlockBuffer/CString::ReleaseBuffer? If I remember right, the things you mentioned should be ok. I can't get to the code right now, but I'll check when I can. Thanks! -Janetta

                    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