开发者

How do I profile memory usage in my project

Are there any good, free tools to profile memory usage in C# ?

Details:

I have a visualization project that uses quite large collections. I would like to check which parts of this project - on the data-processing side, or on the visualization side - use most of the memory, so I could optimize it.

I know that when it comes to computing size of the collection the case is quite simple and I can do it on my own. But there are also certain elements for which I cannot estimate the memory usage so easily.

The memory usage is quite big, for example processing a file of size 35 MB my program uses a little bit more than 250 MB开发者_如何学Python of RAM.


I've had success using RedGate's ANTS profiler. It is also worth reading Brad Abrams blog where he has talked about profiling memory


I'm amazed noone has mentioned the free CLR Profiler from Microsoft!

I didn't know of this tool until recently. I had a bug that made my program keep allocating more and more memory. The CLR Profiler can pinpoint memory-allocating "hot spots" in your program.

I identified the line of code responsible for the leak, within 15-20 minutes of installing the profiler.

Basically, it instruments your code and runs it with some profiling (which slows down your code considerably, 10x-100x are the official figures I think).

You run a certain workload for a certain amount of time, and you can then see which places in your code that allocated how much memory (and how much was freed versus how much was retained etc.).

Check it out at: https://clrprofiler.codeplex.com/

Also, here is a tutorial on how to use the tool: http://geekswithblogs.net/robp/archive/2009/03/13/speedy-c-part-4-using---and-understanding---clr.aspx


JetBrains DotTrace is also good. I have used both the RedGate and JetBrains products and they both do a very good job of identifying the bottlenecks and leaks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜