G
Guest
Hi guys,
I just found that ListView leaks memory on a specific ocasion. This is when removing (already inserted) items from the ListView while its window handle is not created yet (or has been destroyed already).
To reproduce this condition it is enough to put a ListView on a tab page which is not initialy visible. Adding items to the ListView is not a problem. Removing thems (again - before the ListView has its handle created!!!) finnishes with no obvious problems too but it leaves the (being removed) items stuck forever in an internal Hashtable collection (listItemsTable).
The source of the problem is in the ListViewItemCollection.RemoveAt(int index) method. The first thing it seems to do is unhosting the removed item from the ListView and later it (unsuccesufuly) removes the item from the internal Hashtable. But unhosted item does not have na ID value any more and therefore can not be located by the Hashtable for removal. So it will sit there forever.
A simple workaround, which I'm using right now, is to force the creation of the handle of all ListView controls before you start adding and removig items to them. When the handle is there the ListView is using the native LVI's ID (which is still in place) as a key when removing the intem from the internal Hastable, so it works.
I did not have the time to search on the web and see if this bug was already reported. My excuses if that's the case, but the issue seems to be present in .NET 2.0 Beta as well.
I'll appreciate appreciate a from somebody from MS since I posted this issue to the GotDotNet group but got no reponse and thus I don know yet if MS aknowledged the issue
Best,
Stefa
I just found that ListView leaks memory on a specific ocasion. This is when removing (already inserted) items from the ListView while its window handle is not created yet (or has been destroyed already).
To reproduce this condition it is enough to put a ListView on a tab page which is not initialy visible. Adding items to the ListView is not a problem. Removing thems (again - before the ListView has its handle created!!!) finnishes with no obvious problems too but it leaves the (being removed) items stuck forever in an internal Hashtable collection (listItemsTable).
The source of the problem is in the ListViewItemCollection.RemoveAt(int index) method. The first thing it seems to do is unhosting the removed item from the ListView and later it (unsuccesufuly) removes the item from the internal Hashtable. But unhosted item does not have na ID value any more and therefore can not be located by the Hashtable for removal. So it will sit there forever.
A simple workaround, which I'm using right now, is to force the creation of the handle of all ListView controls before you start adding and removig items to them. When the handle is there the ListView is using the native LVI's ID (which is still in place) as a key when removing the intem from the internal Hastable, so it works.
I did not have the time to search on the web and see if this bug was already reported. My excuses if that's the case, but the issue seems to be present in .NET 2.0 Beta as well.
I'll appreciate appreciate a from somebody from MS since I posted this issue to the GotDotNet group but got no reponse and thus I don know yet if MS aknowledged the issue
Best,
Stefa