开发者

.net memory measuring and profiling

I understand there are many questions related to this, so I'll be very specific. I create Console application with two instructions. Create a List with some large capacity and fill it with sample data, and then clear that List or make it equal to null. What I want to know is if there is a way for me to know/measure/profile while debugging or not, if the actual memory used by the application after the list was 开发者_Python百科cleared and null-ed is about the same as before the list was created and populated. I know for sure that the application has disposed of the information and the GC has finished collecting, but can I know for sure how much memory my application would consume after this? I understand that during the process of filling the list, a lot of memory is allocated and after it's been cleared that memory may become available to other process if it needs it, but is it possible to measure the real memory consumed by the application at the end? Thanks

Edit: OK, here is my real scenario and objective. I work on a WPF application that works with large amounts of data read through USB device. At some point, the application allocates about 700+ MB of memory to store all the List data, which it parses, analyzes and then writes to the filesystem. When I write the data to the filesystem, I clear all the Lists and dispose all collections that previously held the large data, so I can do another data processing. I want to know that I won't run into performance issues or eventually use up all memory. I'm fine with my program using a lot of memory, but I'm not fine with it using it all after few USB processings. How can I go around controlling this? Are memory or process profilers used in case like this? Simply using Task Manager, I see my application taking up 800 MB of memory, but after I clear the collections, the memory stays the same. I understand this won't go down unless windows needs it, so I was wondering if I can know for sure that the memory is cleared and free to be used (by my application or windows)


It is very hard to measure "real memory" usage on Windows if you mean physical memory. Most likley you want something else like:

  1. Amount of memory allocated for the process (see Zooba's answer)
  2. Amount of Managed memory allocated - CLR Profiler, or any other profiler listed in this one - Best .NET memory and performance profiler?
  3. What Task Manager reports for your application

Note that it is not necessary that after garbage collection is finished amount of memory allocated for your process (1) changes - GC may keep allocated memory for future managed allocations (this behavior is not specific to CLR for memory allcation - most memory allocators keep free blocks for later usage unless forced to release it by some means). The http://blogs.msdn.com/b/maoni/ blog is excelent source for details on GC/memory.


Process Explorer will give you all the information you need. Specifically, you will probably be most interested in the "private bytes history" graph for your process.

Alternatively, it is possible to use Window's Performance Monitor to track your specific application. This should give identical information to Process Explorer, though it will let you write the actual numbers out to a separate file.

.net memory measuring and profiling

(A picture because I can...)


I personaly use SciTech Memory Profiler
It has a real time option that you can use to see your memory usage. It has help me find a number of problems with leaking memory.


Try ANTS Profiler. Its not free but you can try the trial version.


http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜