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