c#垃圾收集。 .NET CLR内存Perfmon计数器显示0代表0的堆大小等。这是什么意思?

时间:2021-01-15 22:53:47

I have been reading about the .NET CLR Memory Performance counters

我一直在阅读有关.NET CLR内存性能计数器的信息

http://msdn.microsoft.com/en-us/library/x2tyfybc(v=vs.110).aspx

http://msdn.microsoft.com/en-us/library/x2tyfybc(v=vs.110).aspx

Lots of counters have the following caveat:

很多柜台都有以下警告:

This counter is updated at the end of a garbage collection, not at each allocation.

I have spotted a memory leak for an app, and checked out the gen 0 heap size, gen 1, # bytes on all heaps and they are displaying as 0. Can this trusted? How can I distinguish between the below two scenarios?

我发现一个应用程序的内存泄漏,并检查了所有堆上的gen 0堆大小,gen 1,#bytes,它们显示为0.这可信吗?如何区分以下两种情况?

  1. A garbage collection has not taken place yet
  2. 垃圾收集还没有发生
  3. My app does not have any gen 0,1 etc allocations ?
  4. 我的应用程序没有任何gen 0,1 etc分配?

1 个解决方案

#1


3  

I would put my money on 1) A garbage collection has not taken place yet.

我会把钱花在1)垃圾收集还没有发生。

I've compared the performance monitor output of the following two scenarios:

我比较了以下两种情况的性能监视器输出:

static void Main(string args[])
{
    Console.ReadLine();
}

In this case, the performance monitor shows 0 bytes in all heaps.

在这种情况下,性能监视器在所有堆中显示0个字节。

with this which shows 22,496 bytes in all heaps.

用这个显示所有堆中的22,496个字节。

static void Main(string args[])
{
    GC.Collect();
    Console.ReadLine();
}

This would suggest that even an empty app in which no memory is directly allocated has some heap allocations.

这表明即使是没有直接分配内存的空app也会有一些堆分配。

You could test this out by placing a call to GC.Collect somewhere in your code.

您可以通过在代码中的某个位置调用GC.Collect来测试它。

#1


3  

I would put my money on 1) A garbage collection has not taken place yet.

我会把钱花在1)垃圾收集还没有发生。

I've compared the performance monitor output of the following two scenarios:

我比较了以下两种情况的性能监视器输出:

static void Main(string args[])
{
    Console.ReadLine();
}

In this case, the performance monitor shows 0 bytes in all heaps.

在这种情况下,性能监视器在所有堆中显示0个字节。

with this which shows 22,496 bytes in all heaps.

用这个显示所有堆中的22,496个字节。

static void Main(string args[])
{
    GC.Collect();
    Console.ReadLine();
}

This would suggest that even an empty app in which no memory is directly allocated has some heap allocations.

这表明即使是没有直接分配内存的空app也会有一些堆分配。

You could test this out by placing a call to GC.Collect somewhere in your code.

您可以通过在代码中的某个位置调用GC.Collect来测试它。