[英]Memory leak in C# winforms app on picturebox
我的应用程序从视频中读取帧(进行一些处理),然后将其显示在图片框中-每秒大约完成10次,现在我遇到了一个问题,即无法正确处理图片框图像。
我遇到内存泄漏,最终出现内存不足异常。
//Check if PictureBox already contains an image, if so dispose of it.
if (VideoDisplay.Image != null)
{
VideoDisplay.Image.Dispose();
}
//set parameter to the new image
displayImage = OverlayImage.UpdateImage(eventArgs.Frame, WarningText, WarningBrush);
//set the picturebox to the new image
VideoDisplay.Image = displayImage;
//dispose of brush & start garbage collector
WarningBrush.Dispose();
GC.Collect();
通过注释掉VideoDisplay.Image = displayImage
行,内存泄漏停止了(但显然我没有图像)。
只是想知道是否有人可以帮我解决这个问题,因为我以前从未处理过物体等,也不知道我在处理时是否犯了错误或错过了什么。
通过删除VideoDisplay.Dispose()找到了答案,并对其进行了修复。 通过快速查找,可能已锁定了GC无法收集的对象。
在更新映像之前,您需要处理它。 我有类似的问题。
像这样:
VideoDisplay.Image.Dispose();
在那行代码之后,更新映像。 对于您的方案:
VideoDisplay.Image = displayImage;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.