![]() |
CXTCheckListBox::SetCheck memory leak |
Post Reply
|
| Author | |
craig
Groupie
Joined: 11 August 2005 Location: United States Status: Offline Points: 44 |
Post Options
Thanks(0)
Quote Reply
Topic: CXTCheckListBox::SetCheck memory leakPosted: 30 November 2005 at 3:42pm |
|
When I call CXTCheckListBox::SetCheck in my dialog, it causes a memory leak. Is there a workaround for this?
CXTChecklistbox m_checklistBox; // in header file m_checklistBox.Initialize(); // In OnInitInstance int index = m_checklistBox.AddString("test") // In OnInitInstance or elsewhere m_checklistBox.SetCheck(index, TRUE); // In OnInitInstance or elsewhere Cancel out of the dialog, exit the application, and if you have a mem leak detector running the mem leak will appear. I've done extensive testing and this method is definately where the leak is. Here is the output from mine: Detected memory leaks! Dumping objects -> c:\program files\codejock software\mfc\xtreme toolkitpro v9.80\source\controls\xtchecklistbox.cpp(161) : {4449} normal block at 0x0198F290, 12 bytes long. Data: < > 00 00 00 00 01 00 00 00 00 00 00 00 Object dump complete.
|
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 01 December 2005 at 5:07am |
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
craig
Groupie
Joined: 11 August 2005 Location: United States Status: Offline Points: 44 |
Post Options
Thanks(0)
Quote Reply
Posted: 01 December 2005 at 11:00am |
|
I'll add my memory checker to your code and check it again.
|
|
![]() |
|
craig
Groupie
Joined: 11 August 2005 Location: United States Status: Offline Points: 44 |
Post Options
Thanks(0)
Quote Reply
Posted: 01 December 2005 at 1:40pm |
|
The code you provided fails on ASSERT on line 226 in XTCheckListBox.cpp when it is compiled and run under Visual Studio .NET 2003 and Windows XP SP2.
|
|
![]() |
|
craig
Groupie
Joined: 11 August 2005 Location: United States Status: Offline Points: 44 |
Post Options
Thanks(0)
Quote Reply
Posted: 01 December 2005 at 6:00pm |
|
I build a demo app myself, and cannot reproduce the leak. I've compared my project to the sample project looking for anything that might cause memory to be handled differently between the two projects and cannot find anything. Yet... In my project I am definately seeing a memory leak. Line 160 in xtchecklistbox.cpp is where the leak is being allocated: if (pState == NULL)pState = new CHECK_DATA; Do you have any ideas at all as to why this widget would be leaking memory in my dialog, and not leak it elsewhere? Its just a regular old CDialog. I've been poring through code for 2 days, and just cannot determine what might be causing this. The only other area I have trouble is in an external lib that is built with /MD. I can't use new/delete to create objects in that DLL, but I don't see how that would relate to this at all. --Craig
|
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 02 December 2005 at 12:49am |
|
Hi, Strange, I don't see ASSERT in Visual Studio 2003 too... May be you need to recompile library or smth... Hint to find problem in your sample: try to set brakpoint in void CXTCheckListBox::PreDeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct)and check if it called. |
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
craig
Groupie
Joined: 11 August 2005 Location: United States Status: Offline Points: 44 |
Post Options
Thanks(0)
Quote Reply
Posted: 02 December 2005 at 4:37pm |
|
The Assert was happening because the listbox had OwnerDraw set to No instead of Variable and HasStrings was set to False instead of True. Hurray! I figured out why it is breaking, but I'm not sure how to fix it. I had put a break point in PreDeleteItem yesterday (at 11:30 pm :-( ) and it was never stopping there. With your post above, I took another look. In my dialog box, I have several controls but the two that are involved in this scenario are the CXTCheckListBox and a CXTEditListBox w/ a toolbar. When an item in the CXTCheckListBox is "checked" it is added to the CXTEditListBox. When an item in the CXTEditListBox is "deleted" it is unchecked in the CXTCheckListBox . In order to accomplish this, I captured the WM_DELETE event in my dialog. This is having two bad side-effects: 1. It was grabbing the Delete message that the CXTCheckListBox needs, and consequently caused the memory leak. 2. WM_DELETE is generated not just when an item in the CXTEditListBox is deleted, but also when it is moved up, moved down, or the text is edited. My capturing of this event was corrupting those actions as well. How can I capture when an item is deleted from a CXTEditListBox via the Red X on the toolbar without corrupting everything else? Thanks! afx_msg void CFileImportDlg::OnDeleteItem(int nIDCtl, LPDELETEITEMSTRUCT lpDeleteItemStruct) { if (lpDeleteItemStruct->CtlID == IDC_IMPORT_DST_ATTRIBUTES) { int srcIndex = lpDeleteItemStruct->itemData; m_srcAttributes.SetCheck(srcIndex,FALSE); } }
|
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 03 December 2005 at 4:19am |
|
Hi, CXTEditListBox seds LBN_XT_DELETEITEM after item deleted using Delete Button, catch it instead: ON_LBN_XT_DELETEITEM(IDC_EDIT_LIST, OnDeleteItem) but unfortunally it doesn't send which item was deleted :(... So you must check all items and find deleted one. |
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
craig
Groupie
Joined: 11 August 2005 Location: United States Status: Offline Points: 44 |
Post Options
Thanks(0)
Quote Reply
Posted: 08 December 2005 at 12:18pm |
|
Thanks. It worked out pretty well. Not having the deleted item resulted in an n squared search, but I'm pretty sure that n will remain small so I should be OK. --Craig
|
|
![]() |
|
Post Reply
|
|
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |