wxListCtrl::SetItemData Memory Leak

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
radez
Knows some wx things
Knows some wx things
Posts: 31
Joined: Fri Nov 05, 2004 1:35 pm
Location: NC, USA

wxListCtrl::SetItemData Memory Leak

Post by radez » Wed Dec 22, 2004 4:42 pm

Has anyone had any experience with the ListCtrl SetItemData?

I am populating a list from a database and for each item I'm am calling this function:

LstCtrl->SetItemData(ct, atol(res));

(int) ct is my count keeping track of which index I'm on in the list and res is a string returned from my database.

I'm assuming this Data container is for what ever you want to put in it and not anything in particular right?

when I comment this one line out I don't get the memory leak per list entry.

Is there a place to findout if this is bug? I don't know much about bug reporting. Let me know if anyone would like to see more code.

Thanks

Radez
VC++ 7.1.3088 on XP Tablet
as of Dec 2004 - wx2.5.3
as of Nov 2004 - wx2.4.2
as of May 2005 - wx2.6.0
as of June 2005 - wx2.6.1

ConnorMacLeod
Knows some wx things
Knows some wx things
Posts: 39
Joined: Thu Nov 25, 2004 10:10 am
Location: Germany

Post by ConnorMacLeod » Fri Jan 28, 2005 3:59 pm

I have the same problem: memory leak with ListCtrl.

Even the wxWidgets sample of ListCtrl has a memory leak so i assume that's a wx bug.
[wxMSW 2.6.1/VC7.1 .NET 2003/WinXP]

rex666
Earned a small fee
Earned a small fee
Posts: 20
Joined: Mon Nov 08, 2004 12:15 am

Post by rex666 » Tue Jun 21, 2005 7:58 am

The problem seems to be in the wxListCtrl::MSWOnNotify method

It sets the count to zero before the event is sent, and then tries to clean up the user data after, but because the count was already set to zero, wxListCtrl::FreeAllInternalData doesn't free anything.

I moved the m_count = 0 line to be after the call to FreeAllInternalData() that happens in the post-processing of the MSWOnNotify call, and it seems to work better.

In wxWidgets 2.5.3, the change is:
src\msw\listctrl.cpp:
comment out line 1905
add at line 2180:
m_count = 0;

Avi
Super wx Problem Solver
Super wx Problem Solver
Posts: 398
Joined: Mon Aug 30, 2004 9:27 pm
Location: Tel-Aviv, Israel

Post by Avi » Tue Jun 21, 2005 8:09 am

Create a proper patch and post it on the SF.net Patches tracker :wink:

rex666
Earned a small fee
Earned a small fee
Posts: 20
Joined: Mon Nov 08, 2004 12:15 am

Post by rex666 » Tue Jun 21, 2005 4:15 pm

This is a stupid question, but how do I create a patch?

Thanks
-robin

Avi
Super wx Problem Solver
Super wx Problem Solver
Posts: 398
Joined: Mon Aug 30, 2004 9:27 pm
Location: Tel-Aviv, Israel

Post by Avi » Tue Jun 21, 2005 7:10 pm

I can assure you we all asked that question... You can find the information here: http://www.wxwidgets.org/technote/patches.htm

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton » Tue Jun 21, 2005 7:22 pm

Avi wrote:I can assure you we all asked that question... You can find the information here: http://www.wxwidgets.org/technote/patches.htm
Heck, I don't know why I didn't put this in the FAQ sooner
[Mostly retired moderator, still check in to clean up some stuff]

rex666
Earned a small fee
Earned a small fee
Posts: 20
Joined: Mon Nov 08, 2004 12:15 am

Post by rex666 » Sat Jun 25, 2005 2:26 am

I see it has already been fixed in 2.6.1

Thanks
-robin

Post Reply