CString and memory leak
In my project, I have following class member function
void CIconButton::Initialize(int nBitmapID, int nImgWidth,LPCTSTR
sTooltip)
{
CBitmap bmp;
bmp.LoadBitmap(nBitmapID);
BITMAP scBkgBitmap;
bmp.GetBitmap(&scBkgBitmap);
m_ImageList.Create(nImgWidth, scBkgBitmap.bmHeight, ILC_COLOR24|
ILC_MASK, 1, 1);
ASSERT(m_ImageList.m_hImageList);
m_ImageList.Add( &bmp, RGB(255,0,255));
bmp.DeleteObject();
m_sTooltip = sTooltip;
m_objTooltip.CreateTooltip(this);
}
I am calling this function by
m_btnFilter.Initialize(IDB_SLICER_BTN,22,L"Clear Filter (ALT+C) ");
After execution of the project terminates ouput window shows following
memory leak:
---------- Block 202601 at 0x0B8FD348: 82 bytes ----------
Call Stack:
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\strcore.cpp
(141): CAfxStringMgr::Allocate
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\include\atlsimpstr.h
(718): ATL::CSimpleStringT<wchar_t,1>::Fork
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\include\atlsimpstr.h
(756): ATL::CSimpleStringT<wchar_t,1>::PrepareWrite2
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\include\atlsimpstr.h
(743): ATL::CSimpleStringT<wchar_t,1>::PrepareWrite
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\include\atlsimpstr.h
(491): ATL::CSimpleStringT<wchar_t,1>::Preallocate
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\include\atlsimpstr.h
(604): ATL::CSimpleStringT<wchar_t,1>::SetString
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\include\atlsimpstr.h
(581): ATL::CSimpleStringT<wchar_t,1>::SetString
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\include\atlsimpstr.h
(318): ATL::CSimpleStringT<wchar_t,1>::operator=
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\include\cstringt.h (985):
ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t>
0x03753948 (File and line number not available): (Function name
unavailable)
0x02EE4EBF (File and line number not available): (Function name
unavailable)
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\wincore.cpp
(2009): CWnd::OnWndMsg
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\wincore.cpp
(1745): CWnd::WindowProc
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\wincore.cpp
(241): AfxCallWndProc
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\wincore.cpp
(389): AfxWndProc
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\afxstate.cpp
(209): AfxWndProcBase
0x7E418734 (File and line number not available): GetDC
0x7E42BDF1 (File and line number not available): UserLpkPSMTextOut
0x7E428EA0 (File and line number not available): DefWindowProcW
0x7E42CE7C (File and line number not available):
SetLayeredWindowAttributes
0x7C90E453 (File and line number not available):
KiUserCallbackDispatcher
0x7E42E442 (File and line number not available): GetScrollInfo
0x7E42D0D6 (File and line number not available): CreateWindowExW
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\wincore.cpp
(692): CWnd::CreateEx
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\wincore.cpp
(741): CWnd::Create
0x037552E3 (File and line number not available): (Function name
unavailable)
0x0375D4CC (File and line number not available): (Function name
unavailable)
0x02F002F2 (File and line number not available): (Function name
unavailable)
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\wincore.cpp
(2013): CWnd::OnWndMsg
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\wincore.cpp
(1745): CWnd::WindowProc
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\wincore.cpp
(241): AfxCallWndProc
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\wincore.cpp
(389): AfxWndProc
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\afxstate.cpp
(209): AfxWndProcBase
0x7E418734 (File and line number not available): GetDC
0x7E418816 (File and line number not available): GetDC
0x7E4189CD (File and line number not available): GetWindowLongW
0x7E418A10 (File and line number not available): DispatchMessageW
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\thrdcore.cpp
(188): AfxInternalPumpMessage
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\thrdcore.cpp
(916): CWinThread::PumpMessage
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\thrdcore.cpp
(637): CWinThread::Run
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\appcore.cpp
(701): CWinApp::Run
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\winmain.cpp (49):
AfxWinMain
f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\src\mfc\appmodul.cpp
(25): wWinMain
f:\vs70builds\3077\vc\crtbld\crt\src\crtexe.c (390):
wWinMainCRTStartup
0x7C817067 (File and line number not available):
RegisterWaitForInputIdle
Data:
B8 AE 43 7C 20 00 00 00 20 00 00 00 01 00 00
00 ..C|.... ........
43 00 6C 00 65 00 61 00 72 00 20 00 46 00 69 00
C.l.e.a. r...F.i.
6C 00 74 00 65 00 72 00 20 00 28 00 41 00 4C 00
l.t.e.r. ..(.A.L.
54 00 2B 00 43 00 29 00 20 00 4D 00 65 00 6D 00 T.
+.C.). ..M.e.m.
6F 00 72 00 79 00 20 00 4C 00 65 00 61 00 6B 00
o.r.y... L.e.a.k.
00
00 ........ ........
If I comment following line
m_sTooltip = sTooltip;
then memory leak doesn't occur.
What is the problem?
If a create another simple dialog box project in visual studio.NET and
do the same thing (i.e assign CString object to another CString member
variable )than memory leak doesn't occur.????
Than what is the issue in main project??