标签:ras variable github hat roo bottom demo asi resource
https://www.tessferrandez.com/blog/2008/03/25/net-debugging-demos-lab-7.html
This is the last debugging lab in the .NET Debugging Labs series. By now you should have the basics down for troubleshooting hangs, perf issues, memory leaks and crashes in .net applications. Hope you have enjoyed your debugging sessions.
The last one in the series is a managed memory leak caused by holding on to resources in an unexpected way. Since it is the last one I have tried to make the questions a little bit less leading than the previous ones :)
If you are new to the debugging labs, here you can find information on how to set up the labs as well as links to the previous labs in the series.
The problem description is very similar to Lab 6.
We have started getting out of memory exceptions on the Buggy Bits site and we have been able to determine a scenario in which we think we are leaking memory but we can’t seem to figure out where the memory is going.
The leak seems to be occurring on our News page for example and we can reproduce it by stress testing.
It seems like it is leaking just a small bit every time but since it is something that customers look at a lot and over time the process will crash with an out of memory exception.
Stress the application
.\tinyget.ps1 -url https://localhost:44350/News -numTimes 1000
After tinyget has finished, capture a memory dump
dotnet-dump collect -n iisexpress
or with procdump
procdump64.exe -ma iisexpress.exe
Check Working Set
, GC Heap Size
and Number of Assemblies Loaded
Open the memory dump in WinDbg, load up the symbols and load sos.dll (see information and setup instructions for more info)
Run !eeheap -gc
and !dumpheap -stat
We saw from the performance counters that we appeared to be leaking .net memory, so the next step is to determine what the memory is used for.
Run !dumpheap -stat
!dumpheap -stat
, can you see any patterns among the objects? I.e. can they be grouped in any way?Normally you will be able to see patterns such as many data related objects, many ui related objects, many xml related objects etc. like in this memory investigation
!dumpheap -stat
, do the quantities of each of them seem normal or does anything seem out of the ordinary?Dump the large objects using !dumpheap -min 0n85000
Take any of the objects on the LOH and run !gcroot <object address>
to find out where they are rooted
An example of a root chain would look like this (if we are looking to see why the string at address 02ebf628
is still around)
!gcroot 02ebf628
...
DOMAIN(001CCA88):HANDLE(Strong):2c41188:Root: 02ec05c0(MyNamespace.Person)->
02ec0578(MyNamespace.Address)->
02ebf628(System.String)
In this case we have a strongly rooted (static) object of type MyNamespace.Person
at 02ec05c0
. Person
has a member variable of type Address
at 02ec0578
and Address
has a member variable of type string
at 02ebf628
, so the reason that the string is still around is because it is linked to an Address that is linked to a Person and that Person is stored as a static variable. Unless the chain is broken the string will not be available for collection until the application domain is recycled since static objects never go out of scope.
Look at the root chain of the object that you did !gcroot
on.
Note: If you walk it from the bottom up and reach an object type that you don’t recognize, look it up on the docs to get more info about it in order to understand why there is a link.
Look at the code for the News controller and use the knowledge you gathered from the debugging session to figure out how the leak was generated.
Have fun,
Tess
Categories: blog
Updated: March 25, 2008
.NET Debugging Demos Lab 7: Memory Leak
标签:ras variable github hat roo bottom demo asi resource
原文地址:https://www.cnblogs.com/micro-chen/p/14823043.html