You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WinDbg中SOS仅转储Gen2/LOH堆的命令及统计分析方法

WinDbg SOS Tool: Gen2 & LOH Summary, Object Stats, and Targeted Dumps

Hey there! Let's walk through exactly how to get the Gen2 and LOH insights you need using SOS in WinDbg, based on your scenario with 20 GC heaps.

1. Get Overall Summary and Object Statistics for Gen2 & LOH

Step 1: Extract Total Size for Gen2 and LOH

First, re-run !eeheap -gc—while you see per-heap details upfront, the final section of the output includes an aggregated summary across all heaps. Look for lines like:

Total Size: Size: 0x12345678 (301989880) bytes.

Gen 0 Heap Size: Size: 0xabcdef (1125937) bytes.
Gen 1 Heap Size: Size: 0x123456 (1193046) bytes.
Gen 2 Heap Size: Size: 0x789abc (8088636) bytes.
LOH Heap Size: Size: 0xdef123 (14680063) bytes.

This gives you the combined size of Gen2 and LOH across all 20 heaps at a glance.

Step 2: Statistically Analyze Objects in Gen2 & LOH

To break down which objects are consuming memory in these regions, use the !dumpheap command with targeting parameters:

For Gen2 Objects

Run this command to get a sorted (by size) breakdown of object types, instance counts, and total memory usage in Gen2 across all heaps:

!dumpheap -stat -gen 2

For LOH Objects

Similarly, this command gives you a statistical overview of large objects (>=85KB by default) in the LOH across all heaps:

!dumpheap -stat -loh

If You Need Per-Heap Object Stats

If you want to drill into a specific heap's Gen2/LOH objects, first grab the address ranges from !eeheap -gc (e.g., note generation 2 starts at and Large object heap starts at for Heap 0). Then use:

!dumpheap -stat -start <gen2_start_addr> -end <gen2_end_addr>

Or for a specific heap's LOH:

!dumpheap -stat -start <loh_start_addr> -end <loh_end_addr>

2. Dump Only Gen2 and LOH Heap Contents

To get a full list of every individual object in Gen2 or LOH (instead of just stats), use these commands:

Dump All Gen2 Objects

This lists every object in Gen2 across all 20 GC heaps, including their addresses, method tables, and sizes:

!dumpheap -gen 2

Dump All LOH Objects

This lists every large object in the LOH across all heaps:

!dumpheap -loh

Dump Specific Heap's Gen2/LOH

If you need to target a single heap's Gen2 or LOH, use the address ranges from !eeheap -gc with:

!dumpheap -start <gen2_start_addr> -end <gen2_end_addr>

Or for a specific heap's LOH:

!dumpheap -start <loh_start_addr> -end <loh_end_addr>

Quick Pro Tip

If you want to combine Gen2 and LOH dumps into a single output file, start by running .logopen C:\temp\gen2_loh_dump.txt in WinDbg, then execute the dump commands—everything will be saved to the specified file.

内容的提问来源于stack exchange,提问作者Sky Line

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:42:19