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. CMemoryState

CMemoryState

Scheduled Pinned Locked Moved C / C++ / MFC
c++performancequestion
5 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.
  • C Offline
    C Offline
    ComboController
    wrote on last edited by
    #1

    ;)Hi, newbie here, I was wondering what's the best way to use the CMemoryState object to check for memory leaks in a MFC program. I want to set a checkpoint at the very beginning of the program and the very end, so in what functions should I call oldState.Checkpoint() and newState.Checkpoint()?

    D 1 Reply Last reply
    0
    • C ComboController

      ;)Hi, newbie here, I was wondering what's the best way to use the CMemoryState object to check for memory leaks in a MFC program. I want to set a checkpoint at the very beginning of the program and the very end, so in what functions should I call oldState.Checkpoint() and newState.Checkpoint()?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Call the CheckPoint() method of a CMemoryState object where you want to start tracking. At the point where you want to stop tracking, call the CheckPoint() method of a second CMemoryState object. Then, call the Difference() method of a third CMemoryState object, passing to it the other two CMemoryState objects.


      Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

      C 1 Reply Last reply
      0
      • D David Crow

        Call the CheckPoint() method of a CMemoryState object where you want to start tracking. At the point where you want to stop tracking, call the CheckPoint() method of a second CMemoryState object. Then, call the Difference() method of a third CMemoryState object, passing to it the other two CMemoryState objects.


        Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

        C Offline
        C Offline
        ComboController
        wrote on last edited by
        #3

        I know how to use the functions, I want to know where is the best place to call them in the App. I was calling the oldState.Checkpoint() in the App() and newState.Checkpoint() in App::ExitInstance() but it returned a difference. When I called oldState.Checkpoint() it listed (I think) a CDocTemplateManager object and a CSingleDoctemplate object....... So this is obviously not the best place to call oldState.DumpAllObjectsSince() to check overall memory usage. Is there a function after App::ExitInstance to do the difference check in?

        S 1 Reply Last reply
        0
        • C ComboController

          I know how to use the functions, I want to know where is the best place to call them in the App. I was calling the oldState.Checkpoint() in the App() and newState.Checkpoint() in App::ExitInstance() but it returned a difference. When I called oldState.Checkpoint() it listed (I think) a CDocTemplateManager object and a CSingleDoctemplate object....... So this is obviously not the best place to call oldState.DumpAllObjectsSince() to check overall memory usage. Is there a function after App::ExitInstance to do the difference check in?

          S Offline
          S Offline
          Steve S
          wrote on last edited by
          #4

          Generally speaking, in a DEBUG build you'll get this behaviour anyway providing your CPP files have the '#define new ....' stuff in them. Are you calling CheckPoint before or after calling the base ExitInstance()? Steve S

          C 1 Reply Last reply
          0
          • S Steve S

            Generally speaking, in a DEBUG build you'll get this behaviour anyway providing your CPP files have the '#define new ....' stuff in them. Are you calling CheckPoint before or after calling the base ExitInstance()? Steve S

            C Offline
            C Offline
            ComboController
            wrote on last edited by
            #5

            I don't know what you mean by '#define new..." I'm overriding the MFCApp::ExitInstance() function and calling the base ExitInstance(). Then I do the object dump, so I can't see why a few objects are still allocated. BTW I am extremely paranoid about memory leaks after having lots of trouble with my last PC (crashing.......sloooowdown etc..)

            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