I want to dispose of a control I'm dynamically adding to my app. The garbage collector is not picking up the object after I .Remove() it from its parent control, and it has huge bitmaps and geometry private members.
I want to be able to do something like this:
foreach (ScrollItem mylabel in canvas1.Children)
{
if (mylabel.bRemove == true)
{
canvas1.Children.Remove(mylabel);
mylabel = null; // or mylabel.Dispose();
}
}
canvas1 can't have null items in a UIObjectCollection so I can't set it to null, and if I just Remove() it the garbage collector doesn't collect it.
I tried to do something like:
myobj = mylabel;
canvas1.Children.Remove(mylabel);
myobj = null;
but that doesn't work either.