c#的winform程序主动触发垃圾回收释放内存

调用屏幕拷贝时内存占用持续增加

private Bitmap GetScreenCapture()
{
    Rectangle tScreenRect = new Rectangle(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
    Bitmap tSrcBmp = new Bitmap(tScreenRect.Width, tScreenRect.Height); // 用于屏幕原始图片保存
    Graphics gp = Graphics.FromImage(tSrcBmp);
    gp.CopyFromScreen(0, 0, 0, 0, tScreenRect.Size);
    gp.DrawImage(tSrcBmp, 0,0,tScreenRect,GraphicsUnit.Pixel);
    return tSrcBmp;
}

上面的函数随人能够进行屏幕拷贝,但是内存持续增加(定时器内部周期调用)

参考

02 C#截图操作(几种截图方法)-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/weixin_36381867/article/details/79434143

主动内存回收

c#的winform程序主动触发垃圾回收释放内存-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/fuck487/article/details/106824034

但是调用内存回收不能太过频繁(比如100ms调用一次,运行一段时间后就不进行内存gc了)

你可能感兴趣的:(笔记,c#,内存回收,垃圾回收,主动回收)