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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值