Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the different CLR handle types?

I've been watching Mario Hewardt's Pluralsight course on .NET Internals and Advanced Debugging Techniques and I've come across the concept of handles in the CLR.

Now I've already found this awesome SO answer about what a handle is, however Mario refers to the handle types:

  • Strong Handle
  • Pinned Handle
  • Async Pinned Handle (SO description)
  • Ref Count Handle
  • Weak Long Handle
  • Weak Short Handle
  • Other Handle

Which aren't really explained in the video and I assume are expected knowledge for those taking this course.

I did a Google and couldn't really find a satisfactory description of what these are, so I was hoping an SO user could help me out.

like image 452
jacobappleton Avatar asked Mar 22 '23 12:03

jacobappleton


1 Answers

I have found this in my notes for windbg:

  • #ESP - ESP=Extended Stack Pointer, Object is in use on a stack (attention, !gcroot may return false positives here, read !help gcroot in windbg)

  • #DOMAIN(x):HANDLE(Strong) - Strong reference, Typically a static variable

  • #DOMAIN(x):HANDLE(WeakLn) - Weak Long Handle, A weak reference that is tracked through finalization (can be resurrected)

  • #DOMAIN(x):HANDLE(WeakSh) - Weak Short Handle, A weak reference, can't be resurrected

  • #DOMAIN(x):HANDLE(Pinned) - Pinned object, pinned at a specific address, can't move around during garbage collection.

  • #DOMAIN(x):HANDLE(RefCnt) - Reference count, referenced as long as the reference count is > 0.

I've taken it long time ago from some MSDN blog I believe, it could have been Tess', but I can't trace it exactly at the moment. (BTW, if you're into .net debugging and you don't know it yet and want to use windbg/sos/sosex, this is the place to learn).

Alejandro Campos Magencio has also a fine series of articles on debugging with windbg and sos; in part 3 you can find there some confirmations of definitions of most of GC Handle types.

like image 80
Aleksander Avatar answered Mar 31 '23 17:03

Aleksander