I am wondering about Marshal.GetFunctionPointerForDelegate. Namely I want to know how it converts a delegate to a function that is non static into a function pointer.
Does it dynamically generate a code stub that has the instance attached somehow? And if so, doesn't this leak memory? Perhaps the delegate frees it in its finalizer?
It doesn't look like System.Delegate has a finalizer, so I am very interested in how this mechanism works. I would assume that it would take 4 bytes for the function pointer and 4 bytes for the instance (on 32-bit), yet it returns a simple IntPtr.