I'm trying to implement a log message system for a 3d engine, it's using std::queue to store the messages.
But i'm getting this wierd memory leak message from CrtDbg, the code looks completley safe tome, so need
some fresh eyes on this,
I'll show you a test program i wrote to demonstrate the leak:
#include <iostream>
#include <string>
#include <queue>
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#define MYDEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )
#define new MYDEBUG_NEW
First try:int main()
{
{
std::queue<LogMessage> q;
q.push(LogMessage(0, 0, "leaky"));
q.pop();
}
_CrtDumpMemoryLeaks();
return 0;
}
The "leak" may also be unrelated to your code, the main preamble allocates some static data that is often falsely reported as a leak.
Thanks, adding brackets did work!
So i guess i must have some problems with the destucion of the class i'm using it then, wich is also wierd, couse i tried setting a breakpoint in the destructor to make sure it's called, and it is.
Guess i'll have to investigate it futher...
Finally fixxed it. And it was a "false" leak.
Had a class declared in main wich wasn't destructed untill the end ('}')
and i called _CrtDumpMemoryLeaks() before it's destructor.
Thank's again Antheus, i added brackets in the code to forced destruction earlier and it works like a charm.