Project targets the .NET Framework 4.8
I have a UserControl with DoubleBuffered = true. When the calling form invalidates the UserControl, the PrivateMemorySize64 increases by 1000 bytes each time. The Paint handler is commented out so that’s not the cause. The test program will crash after 14 hours with an OutOfMemoryException.
using System.Drawing;
using System.Windows.Forms;
public partial class BitmapRender : UserControl
{
private Bitmap TestBmp = new Bitmap(@"D:test.bmp");
public BitmapRender()
{
InitializeComponent();
DoubleBuffered = true; // This line is causing PrivateMemorySize64 to increase
// this.Paint += new System.Windows.Forms.PaintEventHandler(this.This_Paint);
}
/*
private void This_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawImage(TestBmp, 0, 0, this.Width, this.Height);
}
*/
}
MAIN FORM
using System;
using System.Windows.Forms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
// executes every 200 ms
BitmapRender1.Invalidate();// this is causing a memory leak when DoubleBuffered = true in the UserControl;
}
}
I was expecting the PrivateMemorySize64 to stay constant.
3