本文介绍了投票下以运行#应用程序的内存使用情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,运行时,需要查询其自身的内存使用情况。这将是理想的,如果它可以列出的实例每个对象的内存使用情况。我知道这可以通过WMI实现,但我希望的东西不依赖于WMI。

I have an app that, while running, needs to poll its own memory usage. It would be ideal if it could list out the memory usage for each object instantiated. I know this can be achieved by WMI, but I was hoping for something that doesn't rely on WMI.

推荐答案

两个函数你可能会发现有用的:

Two functions you might find useful are:

  GC.GetTotalMemory();
  Process.PagedMemorySize64();



我的经验是,GC.GetTotalMemory()是不是非常可靠。它经常报道的内存使用情况,比实际的内存使用情况小得多。我已经看到了报告,我只用8千兆字节当我的程序运行出的16千兆字节的计算机上的内存。

My experience has been that GC.GetTotalMemory() is not terribly reliable. It often reports memory usage that is much smaller than the actual memory usage. I've seen it report that I'm using only 8 gigabytes when my program runs out of memory on a 16 gigabyte machine.

我还没有测试过程。 PagedMemorySize64,虽然它确实看好。

I haven't yet tested Process.PagedMemorySize64, although it does look promising.

这篇关于投票下以运行#应用程序的内存使用情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 22:28