我怎样才能得到我的C#应用程序使用的实际内存?
How I can get the actual memory used in my C# application?
- 任务管理器显示了不同指标。
- 的Process Explorer 显示增加的专用字节使用情况。
- 性能计数器(perfmon.msc)表现出不同的指标
- 当我用.NET内存分析器,这表明大部分内存被垃圾收集,只有少数直播字节
- Task Manager shows different metrics.
- Process Explorer shows increased usage of private bytes.
- Performance counter (perfmon.msc) showed different metrics
- when I used .NET memory profiler, it showed most of the memory is garbage collected and only few Live bytes.
我不知道该相信哪个好。
I do not know which to believe.
推荐答案内存使用情况是有些不是显示一个数字或两个以上复杂。我建议你看一看马克Russinovich的优秀帖子的不同种在Windows计数器。
Memory usage is somewhat more complicated than displaying a single number or two. I suggest you take a look at Mark Russinovich's excellent post on the different kinds of counters in Windows.
.NET只会进一步复杂化的问题。 .NET程序的过程只是另一个Windows进程,所以很明显它将拥有所有的常规指标,但除了在CLR充当托管的应用程序内存管理器。因此,根据图中这些数字将改变点。
.NET only complicates matters further. A .NET process is just another Windows process, so obviously it will have all the regular metrics, but in addition to that the CLR acts as a memory manager for the managed application. So depending on the point of view these numbers will vary.
在CLR有效地分配和释放在代表.NET应用程序的大块虚拟内存,然后捧出来给应用程序的内存位作为必要的。所以,当你的应用程序可能会在时间上给定点使用很少的内存此内存可能会或可能不会被释放到操作系统。
The CLR effectively allocates and frees virtual memory in big chunks on behalf of the .NET application and then hands out bits of memory to the application as needed. So while your application may use very little memory at a given point in time this memory may or may not have been released to the OS.
在的在CLR本身使用存储器加载IL顶端,编译IL到本地代码,存储所有类型的信息等。所有这一切都增加了进程的内存占用。
On top of that the CLR itself uses memory to load IL, compile IL to native code, store all the type information and so forth. All of this adds to the memory footprint of the process.
如果你想知道你的托管应用程序使用的内存进行数据的字节数在所有堆柜台是非常有用的。专用字节可用作有点粗略估计为在过程级的应用程序的内存使用情况。
If you want to know how much memory your managed application uses for data, the Bytes in all heaps counter is useful. Private bytes may be used as a somewhat rough estimate for the application's memory usage on the process level.
您可能还需要检查这些相关的问题:
You may also want to check out these related questions:
的stackoverflow/questions/1343374/reducing-memory-usage-of-net-applications/
stackoverflow/questions/1463711/how-to-detect-where-a-memory-leak-is/
更多推荐
C#内存使用率
发布评论