0
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 不收集这个?

4

1 回答 1

1

不可重现 (Fx 4.5)。

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

于 2012-02-16T00:00:32.067 回答