A coworker of mine made the claim that delegates are always pinned in the heap in .net. I can't seem to find any authoritative source on whether this information is true.
Is it true?
This is simply not true. Delegates are not pinned in .Net.
Delegates act as if they are pinned when they are used as a parameter to a PInvoke function. The CLR allocates a native thunk which holds a reference to the delegate. But this reference does not pin the delegate nor does it act as a strong reference to the object.
http://msdn.microsoft.com/en-us/magazine/cc164193.aspx#S7
Do note that pinning an object is not free. It actually incurs a fairly significant cost to the GC. It is fine in small doses but having every .Net delegate be pinned would likely have a very noticeable impact on performance
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With