简体   繁体   中英

Is there a way to identify what component actually allocate memory in a .NET app?

I'm developing an application which I would like to be optimized in all aspect and in that objective I would like it not to take too much memory (today it's 145 Mb which for me (51 Years old) is a lot as I used the ZX81 with 1 (one) Kb...)

So is there a way to identify what component actually allocate memory in a .NET app ? I've noticed that RichTextBox with it's undo capacity is a great consumer but is there a way programmatically or with a visual studio (2017 Entreprise) capability, to get a list of allocated memory by "component" or even by variable ? (The memory windows debug seem to be of no help).

Thanks a lot.

In Visual Studio 2017 go to the Analyze menu and select "Performance Profiler..." :

在此输入图像描述

Then choose ".NET Object allocation Tracking", click "Start":

在此输入图像描述

It will run the application, let it go for a while, then stop it and analyse the result.

You can use DotMemory , it's a great tool for memory leak, memory usage investigation

I also recommend this Microsoft article:

.NET Memory Allocation Profiling with Visual Studio 2012

And this blog post:

Find, Fix, and Avoid Memory Leaks in C# .NET: 8 Best Practices

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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