【发布时间】:2010-08-04 14:50:17
【问题描述】:
谁能解释为什么这个小应用程序的内存使用量不断增加?
static class Program
{
private static System.Timers.Timer _TestTimer;
[STAThread]
static void Main()
{
_TestTimer = new System.Timers.Timer();
_TestTimer.Interval = 30;
_TestTimer.Elapsed += new System.Timers.ElapsedEventHandler(_TestTimer_Elapsed);
_TestTimer.Enabled = true;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
static void _TestTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
string test = "tick";
Trace.WriteLine(test);
test = null;
}
}
谢谢! 鼠兔81
【问题讨论】:
-
我们在这里说话的速度有多快?
-
另外,内存使用量是否稳定/上限在一定水平?
-
@Greg - 你知道我们也不知道
Form1发生了什么。 -
@ChaosPandion:你是对的。空的 _TestTimer_Elapsed 处理程序仍然表现出相同的症状。我的最佳猜测是每次事件触发时都会创建新的 ElapsedEventArgs。
-
@theburningmonk:它从大约 3.544k 开始,10 分钟后,它以 5.384k 进入并稳定下来。我打开 DbgView 观察痕迹,然后突然跳到 6.360k。偶尔,它会丢失几个字节,但不会很多(4 到 16 个字节)
标签: c# .net winforms memory-management timer