본문 바로가기

.NET/Debugging

Windbg툴로 관리힙 메모리 디버깅하기 2

http://blogs.msdn.com/b/alejacma/archive/2009/08/13/managed-debugging-with-windbg-managed-heap-part-2.aspx

이 내용은 위의 기사를 토대로 구성되었으며 상이한 내용이 있을 수 있습니다.


Heap 메모리에 object들을 한번 보죠

여기서 우리는 heap안에 모든 object들을 볼수 있습니다.



0:004> !DumpHeap

Address MT Size

7b463c40 790fd0f0 12

7b463c4c 790fd8c4 36

7b463c70 790fd8c4 20

...

01905378 79119a1c 32

...

02907de0 003d6d48 16 Free

total 12400 objects

Statistics:

MT Count TotalSize Class Name

7b492254 1 12 System.Windows.Forms.VisualStyles.VisualStyleRenderer+ThemeHandle

...

79119a1c 3 96 System.Security.Policy.PermissionRequestEvidence

...

003d6d48 11 164 Free

...

790fd0f0 165 1980 System.Object

...

790fd8c4 7308 435252 System.String

Total 12400 objects

0:004> !do 01905378

Name: System.Security.Policy.PermissionRequestEvidence

...

0:004> !do 02907de0

Free Object

Size 16(0x10) bytes

heap 에 free object가 있음을 주목합시다. Free object들은 GC가 일어났을때 Applicaiton Root에서 더이상 참조 되지 않는 object를 나타냅니다. 그러나 이러한 object들은 아직 메모리 compation이 일어나지 않았고 해제되지 않았습니다. 이러한 공간들은 나중에 GC에 의해 다시 사용될수 있고, 만약  heap메모리에 30%이상의 Free object가 존재한다면 프로세스는 조각화가 이루어지는 고통을 겪게 됩니다.

heap에는 너마나 많은 object들이 있기 때문에 대부분 statics만을 보는편이 낳을수 있습니다.


0:004> !DumpHeap -stat

total 12400 objects

Statistics:

MT Count TotalSize Class Name

7b492254 1 12 System.Windows.Forms.VisualStyles.VisualStyleRenderer+ThemeHandle

...

79119a1c 3 96 System.Security.Policy.PermissionRequestEvidence

...

003d6d48 11 164 Free

...

790fd0f0 165 1980 System.Object

...

790fd8c4 7308 435252 System.String

Total 12400 objects






떄로는 우리는 특별한 Type의 객체들만 볼수 있습니다.

0:004> !Name2EE * System.Security.Policy.PermissionRequestEvidence

Module: 790c2000 (mscorlib.dll)

Token: 0x0200048a

MethodTable: 79119a1c

...

0:004> !DumpHeap -mt 79119a1c

Address MT Size

01901ebc 79119a1c 32

01905378 79119a1c 32

019290c0 79119a1c 32

total 3 objects

Statistics:

MT Count TotalSize Class Name

79119a1c 3 96 System.Security.Policy.PermissionRequestEvidence

Total 3 objects