简体   繁体   English

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

[英]FreeMemory and CPUUsage get memory leaks and system out of memory

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 + "%";
    }
}

Then I am using Timer and calling 然后我使用计时器并调用

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());
}

But becouse of this i get memory leaks and system out of memory exceptions. 但是由于这个原因,我得到了内存泄漏和系统内存不足的异常。 Why GC doesn't collect this? 为什么GC不收集这些?

Not reproducable (Fx 4.5). 不可复制(Fx 4.5)。

The listed code does not cause any memory leak. 列出的代码不会引起任何内存泄漏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM