Presentation is loading. Please wait.

Presentation is loading. Please wait.

Wenjin Xu. BasicsAllocationCollectionFinalization GC Mode Sample.

Similar presentations


Presentation on theme: "Wenjin Xu. BasicsAllocationCollectionFinalization GC Mode Sample."— Presentation transcript:

1 Wenjin Xu

2 BasicsAllocationCollectionFinalization GC Mode Sample

3 Idea Automatic memory management Terms Domain, Heap, Generation 0, Generation 1, Generation 2, Large object heap

4

5 Initial CLR reserve memory for small object heap and large object heap(16MB / 64MB) newobj Allocate memory from heap

6

7 When Generation 0 is full Call GC.Collect() Low memory How Assume all objects are garbage Mark following object are reachable: Static fields Method parameters Local variables CPU registers Strong References Collect

8 When Generation 0 is full Call GC.Collect Low memory AppDomain unload CLR is shutting down

9

10 10 GC WorkstationServer Concurrent Collections “Normal” Background GC

11 Single processor should use default Mode

12 In background garbage collection, ephemeral generations (0 and 1) are collected as needed while the collection of generation 2 is in progress

13 High priority thread GC together, so garbage collection is faster Server garbage collection often has larger size segments

14 Why do we need pinning Interop with unmanaged code How objects get pinned GCHandleType.Pinned Allowed by language syntax, eg. fixed in c# Args get pinned by the interop frame Fragmentation problem

15 Can not disable after enable Global Performance hunt (about <1%) Does not count memory from Marshal.AllocHGlobal

16 Strong Reference Allocate Memory by Marshal

17 查看性能计数器 使用对象池节省新建对象造成的 GC 压力 使用 VSTS 检查内存分配情况 WinDBG + sos Debug vs Release

18 Performance Counter http://msdn.microsoft.com/en- us/library/x2tyfybc.aspx http://msdn.microsoft.com/en- us/library/x2tyfybc.aspxBook CLR via C# 3 rd Edition Source Code http://referencesource.microsoft.com/netframewor k.aspx http://referencesource.microsoft.com/netframewor k.aspx

19


Download ppt "Wenjin Xu. BasicsAllocationCollectionFinalization GC Mode Sample."

Similar presentations


Ads by Google