LLVMSharp
LLVMSharp copied to clipboard
Managing lifetimes of [UnmanagedFunctionPointer] delegates
As per the MSDN documentation, any delegate that's passed to unmanaged code as a function pointer needs to be explicitly kept alive in managed code, since the GC doesn't track pointers on the unmanaged side.
We have many such delegates in LLVMSharp. In LLVMSharp.Api, I intend to have the relevant wrapper classes manage their lifetimes so the user won't have to call GC.KeepAlive() on them. For example, a delegate that logically belongs to a Context will be kept alive privately and will be released only when the Context is Disposed.
Sounds good. Great work on the OOApi, I'm still focusing on getting this runnable on as many platforms, so it's good we're doing non overlapping stuff.