In my program I have the following typedef:
typedef shared_ptr<IFrameObserver> IFrameObserverPtr;
And, later, this line of code:
IFrameObserverPtr myObv(new MyObserver(cameras[0]))
. . . in which MyObserver is created in the constructor of IFrameObserverPtr. The problem is that the MyObserver class creates a 6mB bitmap each time it gets created, and since it's never getting deleted, this causes a pretty severe memory leak (this line gets called 10 times a second).
My question is short and simple: How do I explicitly delete the new MyObserver to save myself from this memory leak?
For a reference as to how utterly horrible my memory leak is, here is my task manager during a partial execution of my program:
EDIT: Okay I've spent the last 2 hours trying to fix this to no avail. Doing . . .
myObv.reset();
. . . didn't work.
Just so everyone can see what's going on inside the MyObserver class, here it is:
class MyObserver : public IFrameObserver
{
public:
HBITMAP hbm;
BITMAPINFOHEADER* bi;
MyObserver(CameraPtr pCamera) : IFrameObserver(pCamera) {};
~MyObserver(){delete hbm;}
HBITMAP GetBMP()
{
return hbm;
}
void FrameReceived ( const FramePtr pFrame )
{
DbgMsg(L"Frame Received\n");
//////////////////////////////////////////////////////////////////////////
////////// Set Bitmap Settings ////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//fileheader
BITMAPFILEHEADER* bf = new BITMAPFILEHEADER;
bf->bfType = 0x4d42;
bf->bfSize = 6054400 + 54;
bf->bfOffBits = 54;
//infoheader
bi = new BITMAPINFOHEADER;
bi->biSize = 40;
bi->biWidth = 2752;
bi->biHeight = -733;
bi->biPlanes = 1;
bi->biBitCount = 24;
bi->biCompression = 0;
bi->biSizeImage = 6054400;
bi->biXPelsPerMeter = 2835;
bi->biYPelsPerMeter = 2835;
bi->biClrUsed = 0;
bi->biClrImportant = 0;
//image data in VmbPixelFormatMono8
VmbUchar_t* imageData;
pFrame->GetImage(imageData);
//////////////////////////////////////////////////////////////////////////
////////// Output File to .bmp ////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
BITMAPINFO* bmi;
bmi = (BITMAPINFO*)bi;
HDC hdc = ::GetDC(NULL);
hbm = CreateDIBitmap(hdc, bi, CBM_INIT, imageData, bmi, DIB_RGB_COLORS);
delete bf;
delete bi;
//free(imageData); //doesn't work, crashes
//delete imageData; //doesn't work, crashes
imageData = NULL; //doesn't crash, but I don't think this frees the memory
DeleteObject(hdc);
}
};
I've tried everything I can think of to free the 5.77 mB this objects makes when it's created, and I cannot figure out how to do it.