简体   繁体   English

.NET 应用程序中的快照收集释放了 memory,幕后发生了什么?

[英]Snapshot collection in .NET app frees the memory, what is happening behind the scenes?

I'm investigating a memory leak in a .NET Winforms application and when collecting a snapshot with my tool I noticed the memory got freed (1GB to 1mb).我正在调查 .NET Winforms 应用程序中的 memory 泄漏,当使用我的工具收集快照时,我注意到 memory 被释放(1GB 到 1mb)。

Here come my doubts... Is it really a memory leak?我的疑惑来了……真的是 memory 泄漏吗? What is the .NET profiler doing when collecting a snapshot that my application is not?在收集我的应用程序没有的快照时,.NET 分析器在做什么? Is it forcing the Garbage Collection?它是否强制垃圾收集? If so I tried doing the same with GC.Collect() but the memory still kept rising.如果是这样,我尝试对 GC.Collect() 做同样的事情,但 memory 仍然不断上升。

Looking forward to your considerations.期待您的考虑。

Thanks!谢谢!

Be careful with GC.Collect() because it does NOT trigger actual garbage collecting.小心GC.Collect()因为它不会触发实际的垃圾收集。 It only tells GC that it would be good to trigger.它只告诉GC触发它会很好。 You can find more information here: https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals?redirectedfrom=MSDN#conditions_for_a_garbage_collection您可以在此处找到更多信息: https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals?redirectedfrom=MSDN#conditions_for_a_garbage_collection

You can try with:您可以尝试:

GC.Collect(2, GCCollectionMode.Forced);

Where 2 is garbage collection generation其中2是垃圾收集生成

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

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