if you track the behavior of the RenderTargetBitmap class using the Resource Monitor , you can see every time this class is called, you lose 500 KB of your memory. my answer to your question: Do not use the RenderTargetBitmap class so many times
You cannot fire an event with saved RenderTargetBitmap memory.
If you really need the RenderTargetBitmap class, just add these lines at the end of your code.
GC.Collect() GC.WaitForPendingFinalizers() GC.Collect()
this may solve your problem:
RenderTargetBitmap rtb = new RenderTargetBitmap((int)(renderWidth * dpiX / 96.0), (int)(renderHeight * dpiY / 96.0), dpiX, dpiY, PixelFormats.Pbgra32); DrawingVisual dv = new DrawingVisual(); using (DrawingContext ctx = dv.RenderOpen()) { VisualBrush vb = new VisualBrush(target); ctx.DrawRectangle(vb, null, new System.Windows.Rect(new Point(0, 0), new Point(bounds.Width, bounds.Height))); } rtb.Render(dv); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect();
source share