Hi,
I have an ItemsPanel extended with my IscrollInfoLogic, ContainerGenerator etc.. (Virtualizing)
The ItemsPanel contains FrameworkElements which have a Property type of Drawing.
If the Item is visible i do:
On the Onrender if the DrawingProperty is not null i go with dc.DrawDrawing(*).
else
If it's not visible i just nullify the Drawing property to be eligible for GC.
The ammount of Ram being used just before the GC starts collecting are insane and even after the collection seems that something is being left.
For being more accurate:
public Drawing PageDraw
{
get
{
return m_PageDraw;
}
set
{
if (m_PageDraw != value)
{
m_PageDraw = value;
InvalidateVisual();
}
}
}
private Drawing m_PageDraw;
protected override void OnRender(DrawingContext dc)
{
base.OnRender(dc);
dc.DrawRectangle(Brushes.LightGray, new Pen(Brushes.Black, 1), new Rect(0, 0, Width, Height));
if (PageDraw != null )
{
dc.DrawDrawing(PageDraw);
}
}
void DummyEllement_Unloaded(object sender, RoutedEventArgs e)
{
PageDraw = null;
}
The Drawing consist of various Bitmaps sometimes small sometimes big.
The results are the same even if i use only small bitmaps.
To avoid long threads consider the following:
1. Wpf native BitmapCache is not being used since i create my BitmapImage with Stream // So no leak or huge number here.
2. The stream and the Bitmap itself are being disposed right after the Drawing is RenderClosed() // Also the stream is a stream inside a stream to avoid the wpf's annoying "ownage stream behavior"