How to work in Net application to identify possible memory optimizations?

We have one Net application, our customers think it is too large-scale deployment. We want to know what will help our memory occupation, and it is possible to do better without giving up completely Net and WPF

We are interested in improving the total size and private working set (PWS) On this issue, I just want to see PWS Vmmap usually reports a PWS of 105 MB This 11mb is the image, 31MB is the heap, 52mb is the managed heap, 7MB is the private data, and the rest is the stack, page table, etc

The biggest prize here is the managed heap We can directly occupy about 8MB of stack heap in our own code (i.e. objects and windows we create and manage) The rest are possible created by the elements of the framework we use Net object

What we want to do is determine which elements of the framework account, and some of these uses may rebuild our system to avoid using them when possible Anyone can suggest how to conduct this survey?

Further clarification:

So far, I have used some tools, including excellent ants profilers and WinDbg and SOS. They allow me to see the objects in the managed heap, but the real interest here is not "what?", But why? "Ideally, I would like to say this:" because we use WCF, 100000 objects are created here. If we write our own local transportation, we can save 8MB of X quality risk and development work. "

It is impossible to execute gcroot on 300000 objects

Solution

WinDbg may be a useful tool Debugging tools for windows are included

After running the application, you can attach WinDbg and browse the managed heap (or you can dump memory and browse offline) It will quickly tell you the object type that consumes the maximum amount of memory

First, you will need to load the SOS extension that enables managed application debugging:

.loadby sos mscorwks

Then you can use! Dumpheap obtains heap information, and the - stat switch gives the overall heap information of which types are allocated:

!dumpheap -stat

-The type parameter gives specific information about the allocation instance of the specified type:

!dumpheap -type System.String

There are some other commands that you may find as follows:

>! Gcroot – tracks the allocated object, backs up its root, and finds out why it is in memory. >! Dumpobj – dumps a specific object so that you can see its contents. >! Eeheap - gives some general heap data

MSDN has a full list of SOS commands and its switch

WinDbg is a very complex tool, but if you search to help you get started, there will be many online tutorials and guides Or, I can recommend John Robbins's book debugging Microsoft Net 2.0 applications, the book in WinDbg and SOS Net debugging function has some good details

If you can load the SOS extension into visual studio instead of inputting it into the instant window, you should be able to use the SOS command directly in the vs Instant window:

.load SOS.dll

You may also find CLR profiler and usage guide helpful

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>