CMemoryState
-
;)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()?
-
;)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()?
Call the
CheckPoint()
method of aCMemoryState
object where you want to start tracking. At the point where you want to stop tracking, call theCheckPoint()
method of a secondCMemoryState
object. Then, call theDifference()
method of a thirdCMemoryState
object, passing to it the other twoCMemoryState
objects.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
Call the
CheckPoint()
method of aCMemoryState
object where you want to start tracking. At the point where you want to stop tracking, call theCheckPoint()
method of a secondCMemoryState
object. Then, call theDifference()
method of a thirdCMemoryState
object, passing to it the other twoCMemoryState
objects.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
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?
-
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?
-
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
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..)