-
Pick a few and find out where they are rooted (i.e. why they can’t be collected) Note: You may want to try a couple different ones.
!gcroot <address of char[]>
0:000> !gcroot 00000122de50f630 Finalizer Queue: 00000122DE50F5C8 -> 00000122DE50F5C8 BuggyBits.Models.Link -> 00000122DE50F5E8 System.Text.StringBuilder -> 00000122DE50F630 System.Char[] Found 1 unique roots (run '!gcroot -all' to see all roots).
- Where are they rooted? Why?
The
Char[]
is a member of aStringBuilder
which in turn is a member of aLink
object, which is rooted in the Finalizzer Queue so it is ready for finalization, just waiting for the finalizer to call its destructor so it can be garbage collected.
- Where are they rooted? Why?
Examine the finalizer queue and the finalizer threadPermalink
-
Look at the finalizer queue
!finalizequeue
```cmd 0:000> !finalizequeue SyncBlocks to be cleaned up: 0 Free-Threaded Interfaces to be released: 0 MTA Interfaces to be released: 0 STA Interfaces to be released: 0 ---------------------------------- ------------------------------ Heap 0 generation 0 has 80 finalizable objects (000001276A6A8228->000001276A6A84A8) generation 1 has 5 finalizable objects (000001276A6A8200->000001276A6A8228) generation 2 has 34 finalizable objects (000001276A6A80F0->000001276A6A8200) Ready for finalization 3660 objects (000001276A6A84A8->000001276A6AF708) ------------------------------ Heap 1 generation 0 has 85 finalizable objects (000001276A7034D0->000001276A703778) generation 1 has 24 finalizable objects (000001276A703410->000001276A7034D0) generation 2 has 2 finalizable objects (000001276A703400->000001276A703410) Ready for finalization 3845 objects (000001276A703778->000001276A70AFA0) ------------------------------ Heap 2 generation 0 has 56 finalizable objects (000001276A6E6EE0->000001276A6E70A0) generation 1 has 11 finalizable objects (000001276A6E6E88->000001276A6E6EE0) generation 2 has 3 finalizable objects (000001276A6E6E70->000001276A6E6E88) Ready for finalization 3971 objects (000001276A6E70A0->000001276A6EECB8) ... Statistics for all finalizable objects (including all objects ready for finalization): MT Count TotalSize Class Name ... 00007ffcf80cee28 16 896 System.Threading.ThreadPoolWorkQueueThreadLocals 00007ffcf7a95650 21 1512 System.Threading.Thread 00007ffcf80337d0 31 1736 System.Buffers.MemoryPoolBlock 00007ffcf7ab4ab8 20 2240 System.Diagnostics.Tracing.EventSource+OverideEventProvider 00007ffcf80be4e0 76 5472 System.Reflection.Emit.DynamicResolver 00007ffcf81d8378 31881 1020192 BuggyBits.Models.Link Total 32123 objects ```
- What objects are listed in the
!finalizequeue
output? Hint: run!help finalizequeue
All objects that have finalizers/destructors are registered with the finalizer queue so that the finalizer will run the destructor once the object is garbage collected unless finalization is supressed in the dispose method.
- How many objects are “ready for finalization”? What does this mean?
32123 objects. So these objects are garbage collected and ready to be finalized. If ready for finalization shows anything above 0 there is a pretty good chance the finalizer is blocked which is why these objects stick around waiting to be finalized, and with them goes all the memory they reference.
- What objects are listed in the