Problem with destructor not being executed
Posted on 2006-03-22
I'm having a weird problem with regard to a destructor which fails to execute when I call delete on the instance.
I have a typedef:
typedef struct STITCHREQUEST
STITCHREQUEST(CImage* a_pImage, CImageCollection* a_pCollection)
Image = a_pImage; // I now own this
Collection = pCollection; // I do not own this
Image = NULL;
Collection = NULL;
Basically I have a process which is capturing frames, and it creates these "stitching requests" which is passed into a worker thread, which saves the image and attaches it to the collection. The process that launches the stitching thread instantiates the CImage but the instance is to be destroyed by the ~STITCHREQUEST() destructor so that it is not killed off before stitching is complete.
I set it up like this:
CImage* pImage = new CImage(hbmFrame);
STITCHREQUEST* pRequest = new STITCHREQUEST(pImage, m_pCollection);
Anyway - the stitching and such all works fine. The problem is I have a memory leak, due to ~CImage() never being executed, inspite of the fact 'delete Image;' within ~STITCHREQUEST() is being executed. I have put breakpoints in both destructors, and ~STITCHREQUEST() is executed, both pointers are set to null, but I am very certain that ~CImage() is never run.
Any idea why the CImage destructor isn't called inspite of the fact that: delete Image; is executed??? The CImage instancing and destruction work fine elsewhere in my app.