B
Ben
Hi,
I seem to be having a memory management issue with the ListBox control.
Using .NET Memory Profiler, the Clear() method does not appear to actually
remove references to objects in the list box immediately. I have been able
to work around this by clearing the box, adding a dummy string entry, and
then clearing it again.
Here is some code to demonstrate this:
private class TestObj
{
public override string ToString()
{
return "Testing";
}
}
private void btnAdd_Click(object sender, System.EventArgs e)
{
listBox1.Items.Add(new TestObj());
}
// This does not appear to work!
private void btnClear_Click(object sender, System.EventArgs e)
{
listBox1.Items.Clear();
GC.Collect();
}
private void btnReset_Click(object sender, System.EventArgs e)
{
listBox1.Items.Clear();
listBox1.Items.Add("");
listBox1.Items.Clear();
GC.Collect();
}
Is this a bug in the ListBox, or is it by design?
Ben
I seem to be having a memory management issue with the ListBox control.
Using .NET Memory Profiler, the Clear() method does not appear to actually
remove references to objects in the list box immediately. I have been able
to work around this by clearing the box, adding a dummy string entry, and
then clearing it again.
Here is some code to demonstrate this:
private class TestObj
{
public override string ToString()
{
return "Testing";
}
}
private void btnAdd_Click(object sender, System.EventArgs e)
{
listBox1.Items.Add(new TestObj());
}
// This does not appear to work!
private void btnClear_Click(object sender, System.EventArgs e)
{
listBox1.Items.Clear();
GC.Collect();
}
private void btnReset_Click(object sender, System.EventArgs e)
{
listBox1.Items.Clear();
listBox1.Items.Add("");
listBox1.Items.Clear();
GC.Collect();
}
Is this a bug in the ListBox, or is it by design?
Ben