您的位置:首页 > 其它

《Advanced .NET Debugging》 读书笔记 Listing 5-1: 简单的内存分配

2010-12-30 21:33 651 查看
程序如下:

using System;
using System.Text;
using System.Runtime.Remoting;

namespace Advanced.NET.Debugging.Chapter5
{
    class Name
    {
        private string first;
        private string last;

        public string First { get { return first; } }
        public string Last { get { return last; } }

        public Name(string f, string l)
        {
            first = f; last = l;
        }
    }

    class SimpleAlloc
    {
        static void Main(string[] args)
        {
            Name name = null;

            Console.WriteLine("Press any key to allocate memory");
            Console.ReadKey();

            name = new Name("Mario", "Hewardt");
           
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
    }
}

1. 在WinDbg内载入05SimpleAlloc.exe

2. 在程序要求按键继续时,执行 .loadby sos.dll mscorwks

3. 执行 !dumpheap此时可以看到heap内的对象分布情况

4. 执行 !dumpheap –type Advanced.NET.Debugging.Chapter5.Name 此时可以看到该类型在heap上的分布情况(此时没有实例化Name对象):





5. 执行 g。

6. 当程序再次要求按键继续时,执行 !dumpheap –type Advanced.NET.Debugging.Chapter5.Name ,可以看到实例化了一个对象:





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐