I have a program that CRTDBG reports as having no leaks, yet, according to Windows Task Manager takes up more memory as time goes on. Even worse is that given enough time, it will crash with exit code -1.
This is a program that's going to be a game engine, right now I'm testing the functions that will unload the level by making it rapidly load and unload levels. This appears to be working, otherwise the entities from the 'last' level would bump into the current ones. The memory doesn't increase when I run the program 'normally' and load one level without unloading until exiting.
It may be of note that loading a level involves reading from the hard drive and opening a file. It might also be important to know that I'm using the Chipmunk physics library, Lua, and OpenGL.
The thing that's making this the most tricky is how CRTDBG won't dump, and it returns 0 at the end of main().
EDIT: Also,开发者_如何学JAVA using Visual Studio 2008.
To me it sounds like you are not really leaking memory, just allocating a lot of it and then freeing it up at the exit.
Perhaps you are holding on to some list of objects that you forget to free/delete between the loading of each level ?
It may be that you're observing the effects of a "smart" allocator that asks the OS for big chunks of memory and suballocates. You might check by replacing the global operator new
and operator delete
. If those tell you that all allocated memory is also deallocated, and yet the process' memory consumption goes up or stays up there, then it's (most probably) the allocator.
Lua's garbage collector collects when it feels like it. If you're not explicitly ordering Lua to do a collection, then memory may build up there without being actually used.
精彩评论