Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - CXTCheckListBox::SetCheck memory leak
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTCheckListBox::SetCheck memory leak

 Post Reply Post Reply
Author
Message
craig View Drop Down
Groupie
Groupie


Joined: 11 August 2005
Location: United States
Status: Offline
Points: 44
Post Options Post Options   Thanks (0) Thanks(0)   Quote craig Quote  Post ReplyReply Direct Link To This Post Topic: CXTCheckListBox::SetCheck memory leak
    Posted: 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.

 

 

Back to Top
Oleg View Drop Down
Senior Member
Senior Member


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 01 December 2005 at 5:07am
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
craig View Drop Down
Groupie
Groupie


Joined: 11 August 2005
Location: United States
Status: Offline
Points: 44
Post Options Post Options   Thanks (0) Thanks(0)   Quote craig Quote  Post ReplyReply Direct Link To This Post Posted: 01 December 2005 at 11:00am

I'll add my memory checker to your code and check it again.

 

 

Back to Top
craig View Drop Down
Groupie
Groupie


Joined: 11 August 2005
Location: United States
Status: Offline
Points: 44
Post Options Post Options   Thanks (0) Thanks(0)   Quote craig Quote  Post ReplyReply Direct Link To This Post 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.

 

Back to Top
craig View Drop Down
Groupie
Groupie


Joined: 11 August 2005
Location: United States
Status: Offline
Points: 44
Post Options Post Options   Thanks (0) Thanks(0)   Quote craig Quote  Post ReplyReply Direct Link To This Post 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

 

 

Back to Top
Oleg View Drop Down
Senior Member
Senior Member


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
craig View Drop Down
Groupie
Groupie


Joined: 11 August 2005
Location: United States
Status: Offline
Points: 44
Post Options Post Options   Thanks (0) Thanks(0)   Quote craig Quote  Post ReplyReply Direct Link To This Post 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!
-Craig

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);

}

}

 

 

Back to Top
Oleg View Drop Down
Senior Member
Senior Member


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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)

void CEditListPage1::OnDeleteItem()
{
 OnSelchangeEditList();
}

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
Back to Top
craig View Drop Down
Groupie
Groupie


Joined: 11 August 2005
Location: United States
Status: Offline
Points: 44
Post Options Post Options   Thanks (0) Thanks(0)   Quote craig Quote  Post ReplyReply Direct Link To This Post 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

 

 

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.063 seconds.