简体   繁体   English

C# .NET - 有没有办法在运行时确定我的应用程序的每个类/对象类型的内存使用情况?

[英]C# .NET - Is there a way to determine my app's memory usage per class/object type in runtime?

I have a C# .NET app running in the cloud (Heroku) and from time to time I'm experiencing memory leaks.我有一个在云(Heroku)中运行的 C# .NET 应用程序,有时我会遇到内存泄漏。

I would like to get a detailed memory usage statistics from my app, in runtime, because I cannot attach a debugger to the remote process.我想在运行时从我的应用程序中获取详细的内存使用统计信息,因为我无法将调试器附加到远程进程。

It would be great if I could get something like the follwing from inside of my C# code during runtime:如果我能在运行时从我的 C# 代码内部获得类似以下内容,那就太好了:

> dumpheap -stat

Statistics:
              MT    Count    TotalSize Class Name
...
00007f6c1eeefba8      576        59904 System.Reflection.RuntimeMethodInfo
00007f6c1dc021c8     1749        95696 System.SByte[]
00000000008c9db0     3847       116080      Free
00007f6c1e784a18      175       128640 System.Char[]
00007f6c1dbf5510      217       133504 System.Object[]
00007f6c1dc014c0      467       416464 System.Byte[]
00007f6c21625038        6      4063376 testwebapi.Controllers.Customer[]
00007f6c20a67498   200000      4800000 testwebapi.Controllers.Customer
00007f6c1dc00f90   206770     19494060 System.String
Total 428516 objects

(source: https://docs.microsoft.com/en-us/dotnet/core/diagnostics/debug-memory-leak ) (来源: https ://docs.microsoft.com/en-us/dotnet/core/diagnostics/debug-memory-leak)

I was unable to find anything so far, neither of: a free library, a third party tool nor a code snippet.到目前为止,我找不到任何东西:免费库、第三方工具或代码片段。

You can use DotMemory .您可以使用DotMemory This tool will show you memory leak suggestion, total memory, memory of each type object...该工具将向您显示内存泄漏建议、总内存、每种类型对象的内存...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM