LParam in a list control
I am trying to create objects and store their pointers in the LParam of my
list control. This all works, but clearly I need to tidy up these objects
when an item is deleted from the list. I have written a DeleteAllItems
method which loops round all the items and clears the list and deletes the
objects so all should be well. Problem is that I get memory leaks when the
app closes, so I am obviously not deleting the objects. My test populates
the list with 5 objects and deletes them, then re-populates with 5 objects
again. I call my DeleteAllItems method once myself, then once automatically
in my OnDestroy() method. I have 10 memory leaks, so they must be the 10
list objects, which means my DeleteAllItems method is not deleting the
lParam objects, but I don't understand why. With a breakpoint in this
method, I can see that my line "delete controlItem" is being run correctly
and enough times, so why doesn't it clear the memory? Can anyone help. My
ControlItemLParam is just a struct with 2 ints at the moment. This is my
DeleteAllItems method:
BOOL ListCtrlProcessSchedule::DeleteAllItems()
{
ControlItemLParam *controlItem;
int count = GetItemCount();
for (int nItem = 0; nItem < count; nItem++)
{
controlItem = (ControlItemLParam*) GetItemData(0);
DeleteItem(0);
delete controlItem;
}
return TRUE; // (BOOL) ::SendMessage(m_hWnd, LVM_DELETEALLITEMS, 0, 0L);
}