ensuring statically allocated memory is destroyed
Posted on 2006-04-18
I have some BYTE* buffer's defined statically in my camera class (for performance reasons)
BYTE* CMyCamera::m_pTempFrameBuffer = new BYTE[iHeight * iWidth]; // 8bit buffer for raw data
BYTE* CMyCamera::m_pBuffer = new BYTE[iHeight * iWidth * iByteStep]; // 24bit buffer for RGB converted data
So these arrays are created, even if CMyCamera is never instantiated. In the cases where CMyCamers is instantiated, I delete and NULL out those buffers in the destructor.
But there are cases where my app never instantiates CMyCamera (if the user never uses it) - so howthen do I ensure they are destroyed to prevent the memory leak?
ie. how do I destroy statically allocated memory like that?