views:

587

answers:

2

I'm getting the memory leak message upon shutdown, saying that I'm leaking 3 of a certain object. Two problems with that, though.

  1. It only happens intermittently. I can run my program, go through the exact same series of steps, (open a data file, display it, and shut down again,) and sometimes the message will show up and sometimes it won't. There's no calls to random() or other "non-deterministic" logic along those code paths.

  2. Code review says that the reported memory leak is impossible; the object's only created within a certain class, and it's freed properly within that class's destructor. (And I instantiate a lot more than three objects of the parent class. And no exceptions get raised during cleanup.)

Adding tracing outputs to the constructor and destructor for this class show that every object created is destroyed, even with the memory manager reporting otherwise. So I can only conclude that this is a false positive. However, adding "RegisterUnexpectedMemoryLeak(self)" to the constructor makes the message go away.

Has anybody seen anything like this before? Any idea what might be causing it? I'm about as certain as I can possibly be that the objects are not leaking, so what's happening instead?

A: 

Create a memory leak that you are certain is in the same function, then watch what the memory manager reports.

BubbaT
+7  A: 

Use fresh FastMM, enable Map file construction in Linker options, define conditional symbol FullDebugMode and rebuild the program. Then go through your steps. On program termination, it should generate file programname__MemoryManager__EventLog.txt with information on where in the program the leaked object was constructed.

gabr