是否有可能来跟踪C#应用程序的内存使用情况,而无需使用分析器?分析器、有可能、应用程序、内存

2023-09-03 02:06:57 作者:爱你不嫌多#

我想编写一个简单的应用程序,它可以跟踪其当前的内存使用量,创建的对象的数量等在C ++中我通常会覆盖新的运营商,但由于显而易见的原因,我不能在C#这样做。有没有办法做到这一点,而无需使用分析器?

I'd like to write a simple application which keeps track of its current memory usage, number of created objects etc. In C++ I'd normally override the new operator, but for obvious reasons I can't do this in C#. Is there any way to do this without using a profiler?

推荐答案

您可能要开始与垃圾收集器。 MSDN有上市这里,可以告诉你如何某些成员做了几件事情,就像得到了内存认为分配,多少次GC已收集的总量。什么比这更先进,比如让你加载的程序集的对象的数量,你必须可能使用一个分析器或写自己的东西。

You might want to start with the Garbage Collector. MSDN has some members listed here that can show you how to do a few things, like get the total amount of memory it thinks is allocated, how many times the GC has collected. Anything more advanced than that, like getting a count of objects of your loaded assembly and you'll have to probably use a profiler or write something yourself.