为什么我的Windows窗体应用程序消耗越来越多的内存时,它是一个空白的应用程序,甚至没有正在使用的用户(我)?
Why is my Windows Forms application consuming more and more memory when it's a blank app and not even being used by the user (me)?
您可能能够重现以下步骤操作:
You may be able to reproduce with these steps:
在打开Visual Studio 2013旗舰版 新建项目
> C#
> Windows窗体应用程序
> .NET框架4.5
添加图片框
到 Form1中
从工具箱
面板
这是我发疯了明显的原因。我的应用程序在约LT开始了,1MB,并在几分钟的事,它是由〜10MB。给它一个几分钟,它的再次到〜40MB。而且它不会停在那里。事实上,我离开它运行在晚上,当我醒来的时候,电脑反应迟钝。
This is driving me nuts for the obvious reason. My app starts off at about <1MB and within a matter of a few minutes, it's up to ~10MB. Give it a few more minutes and it's up again to ~40MB. And it doesn't stop there. In fact, I left it running over night and when I woke up, the PC was unresponsive.
推荐答案
GC未收集未使用的内存,因为它是非常小的。
The GC is not collecting unused memory, since it's is very small.
您可以尝试迫使GC收集(不是一个好的做法,只是为了测试)
You can try forcing the GC collect (not a good practice, just for testing)
public Form1()
{
InitializeComponent();
_timer.Interval = 10000;
_timer.Tick += _timer_Tick;
_timer.Start();
}
void _timer_Tick(object sender, EventArgs e)
{
GC.Collect();
}
在此之后,内存保持在3.2 MB的我的电脑:)
After this the memory stays at 3.2 MB at my PC :)
相关推荐
最新文章