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

发布于 2025-02-04 18:32:27 字数 1106 浏览 1 评论 0原文

我有一个在云(Heroku)中运行的C#.NET应用程序,并且我不时会遇到内存泄漏。

我想在运行时从应用程序中获得详细的内存使用统计信息,因为我无法将调试器附加到远程过程。

如果我可以在运行时从C#代码内部获得类似follwing的东西:(

> 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

来源: https://learn.microsoft.com/en-us/dotnet/core/diabore/diagnostics/debug-memory-leak-leak

我到目前为止都找不到任何东西,均未:免费库,第三方工具和代码段。

I have a C# .NET app running in the cloud (Heroku) and from time to time I'm experiencing memory leaks.

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:

> 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://learn.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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不念旧人 2025-02-11 18:32:27

您可以使用 dotmememory 。此工具将向您显示内存泄漏建议,总内存,每个类型对象的内存...

You can use DotMemory. This tool will show you memory leak suggestion, total memory, memory of each type object...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文