FreeMemory和CPUUsage会导致内存泄漏并导致系统内存不足

时间:2012-02-15 16:31:10

标签: c# out-of-memory perfmon

private float FreeMemory
{
    get { return _nFreeMemory; }
    set
    {
        _nFreeMemory = value;
        statusBarPanelMem.Text = _nFreeMemory + " MB prosto";
    }
}

private int CPUUsage
{
    get { return _nCpuUsage; }
    set
    {
        _nCpuUsage = value;
        statusBarPanelCPU.Text = "CPU poraba " + _nCpuUsage + "%";
    }
}

然后我使用Timer并调用

private void InitialiseCounterRamNetwork()
{
    _cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total", true);
    _ramCounter = new PerformanceCounter("Memory", "Available MBytes", true);
}

private void timerMemProcNetwork_Tick(object sender, EventArgs e)
{
   FreeMemory = _ramCounter.NextValue();
   CPUUsage = Convert.ToInt32(_cpuCounter.NextValue());
}

但是由于这个原因,我得到内存泄漏和系统内存异常。 GC为什么不收集这个?

1 个答案:

答案 0 :(得分:1)

不可复制(Fx 4.5)。

列出的代码不会导致任何内存泄漏。