Hi I’m making a dialog based application in MFC using:
BOOL CClockMasterDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
m_ModeTabs.Create(this,WS_CHILD | WS_VISIBLE, 0);
}
If I destroy m_ModeTabs in CClockMasterDlg::OnInitDialog function after it is created using :
m_ModeTabs.DestroyWindow();
I get no memory but leaks when I place it in CClockMasterDlg::OnDestroy() I get memory leaks, even tough it gets called and returns true.
I don’t believe that OnDestroy is OnInitDialog‘s contrary, but then which function is? There is no OnExitDialog.
Detected memory leaks!
Dumping objects ->
{601} client block at 0x00AEED48, subtype c0, 212 bytes long.
a CMFCVisualManager object at $00AEED48, 212 bytes long
Object dump complete.
The program [5312] ClockMaster.exe: Native has exited with code 2 (0x2).
Even tough the window should be destroyed automatically since it`s not a pointer I still shouldn’t get memory leaks should I? And since placing
m_ModeTabs.DestroyWindow();
in the OnInitDialog function after its created solves the memory leak it cant really be something else causing the trouble can it? Removing the m_ModeTabs.Create(... Also solves the memory leak so I’m quite certain that its m_ModeTabs causing it.
I where actually hitting a bug which is gonna be “fixed in MFC for the next major release of Visual Studio”.
The memory leak occurs when using a CVSListBox in a dialog only mfc application.
Information on the bug and several workarounds can be found here:
https://connect.microsoft.com/VisualStudio/feedback/details/646445/cvslistbox-produces-memory-leaks
http://connect.microsoft.com/VisualStudio/feedback/details/565327/memory-leaks-using-c
And another report on the bug here:
http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/8870974f-1414-4dd7-b7c3-a1c320c0e91e
Quotation from first link: