《Advanced .NET Debugging》 读书笔记 Listing 5-1: 简单的内存分配
2010-12-30 21:33
651 查看
程序如下:
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 ,可以看到实例化了一个对象:
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.exeusing 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();
}
}
}
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 ,可以看到实例化了一个对象:
相关文章推荐
- 《Advanced .NET Debugging》 读书笔记 Listing 6-3: 取得Lock的简单示例
- 《Advanced .NET Debugging》 读书笔记 Listing 6-4: Deadlock的简单示例
- 《Advanced .NET Debugging》 读书笔记 Listing 6-6: Orphaned locks的简单示例
- 《Advanced .NET Debugging》 读书笔记 Listing 5-4: 具有Finalize方法的简单对象
- 《Advanced .NET Debugging》 读书笔记 Listing 5-8: Fragmentation的简单示例
- 《Advanced .NET Debugging》 读书笔记 Listing 5-5: LOH的简单示例
- 《Advanced .NET Debugging》 读书笔记 Listing 5-6: Pining的简单示例
- 《Advanced .NET Debugging》 读书笔记 Listing 3-4/3-5: 为breakpoint.exe程序的AddAndPrint方法加上breakpoint
- 《Advanced .NET Debugging》 读书笔记 Listing 3-1: 调试器的使用
- 《Advanced .NET Debugging》 读书笔记 Listing 4-4: 调试Assembly加载失败的程序
- 《Advanced .NET Debugging》 读书笔记 Listing 5-3: Object的Roots的示例
- 《Advanced .NET Debugging》 读书笔记 Listing 3-2: 如何查看程序的PID
- 《Advanced .NET Debugging》 读书笔记 Listing 3-6: 使用sxe在程序载入mscorwks之后停下来载入sos
- 《Advanced .NET Debugging》 读书笔记 Listing 5-2: GC代龄的示例
- 《Advanced .NET Debugging》 读书笔记 Listing 3-10到3-14: 得到程序中各对象的内容
- 《Advanced .NET Debugging》 读书笔记 Listing 2-5/2-6: 使用debugger找到value type和reference type
- 《Advanced .NET Debugging》 读书笔记 Listing 3-3: 使用debugger调试一个已经在运行的程序
- 《Advanced .NET Debugging》 读书笔记 Listing 3-7: 为notepad设置断点的过程
- 《Advanced .NET Debugging》 读书笔记 Listing 6-8: Orphaned lock的示例
- 《Advanced .NET Debugging》 读书笔记 Listing 4-1/2/3: 调试 FileNotFoundException