SOS 使用总结

SOS是VS提供的内存监测工具,可以在调试时实时监测内存数据。

在使用SOS之前,首先要了解几个常用的调试概念。

托管代码与非托管代码:

Managed Code:

Managed code is code written in one of over twenty high-level programming languages that are available for use with the Microsoft .NET Framework, including C#, J#, Microsoft Visual Basic .NET, Microsoft JScript .NET, and C++. All of these languages share a unified set of class libraries and can be encoded into an Intermediate Language (IL). A runtime-aware compiler compiles the IL into native executable code within a managed execution environment that ensures type safety, array bound and index checking, exception handling, and garbage collection.

常见的托管代码有: 

1. Code that is executed by the CLR.
2. Code that targets the common language runtime, the foundation of the .NET Framework, is known as managed code.
3. Managed code supplies the metadata necessary for the CLR to provide services such as memory management, cross-language integration, code access security, and 4. 4. automatic lifetime control of objects. All code based on IL executes as managed code.
Code that executes under the CLI execution environment.

托管调试: Managed Debugging

仅对托管代码进行调试称为托管调试。

SOS 命令

!load SOS: 启动SOS。仅仅执行托管调试时不能载入SOS。解决办法是在 项目-->属性-->调试 页面打开启用非托管代码调试。加上断点,Debug

!CLRStack -n

!DumpDomain

!DumpObj

!DumpHeap -type className

!DumpMT

!u methodAddress

GCHandleLeaks: 查找可能泄露的句柄

!eeheap查找内存增量中最大的对象信息

!syncblk  查与非托管代码之间的内存泄露

参考连接:Drill into How CLR create Objects http://msdn.microsoft.com/en-us/magazine/cc163791.aspx

                    Son of  Strike: http://msdn.microsoft.com/en-us/library/bb190764(v=vs.110).aspx

                    WinDbg: http://www.cnblogs.com/killmyday/archive/2010/02/22/1671511.html

你可能感兴趣的:(.net,Microsoft,C#,son,of,sos,Strike)