I'm writing some Windows software and when it terminates, I'm getting a lot of incorrect memory leak messages:
Detected memory leaks!
Dumping objects ->
{29745} normal block at 0x02938E38, 36 bytes long.
Data: <, E > 2C 0B 45 10 00 00 00 00 01 00 00 00 01 CD CD CD
{29732} normal block at 0x02938C08, 500 bytes long.
Data: <X)A ` @> 58 29 41 10 00 00 00 00 01 00 00 00 60 93 0B 40
{29721} normal block at 0x028DA8A0, 84 bytes long.
Data: < 1D 0 %i> C8 31 44 10 00 00 00 00 01 00 00 00 30 85 25 69
I'm certain these are false positives. Do you have any suggestions on dealing with this? As the software grows, there are likely to be some actual leaks and finding them will be difficult, to say the least.
Edit:
I should have mentioned that I'm using a library called OpenSceneGraph
. It makes heavy use internally of reference counted smart pointers. All of these leaks are instances that I new
then pass into the library which promptly wraps it in a ref_ptr<>
. I know the instances aren't leaking because I've added fprintf
to the destructor and I do see the message when the smart pointer goes out of scope. Microsoft had a problem like this a while ago with the standard library and I'm wondering if I'm seeing something similar here? Apparently the bug was related to some _CRT_BLOCKS
getting tagged as _NORMAL_BLOCKS
.
Edit 2:
I figured out what's going on. The code that dumps the memory leak information happens before all the static data goes out of scope. In one case an internal object is constructed via the prototype pattern and the prototype object is static and so isn't destroyed until the atexit machinery kicks in. So, nothing is really leaking. It's just that the dump is happening before the app tear-down happens.