Without pointing me to MSDN, could someone give a concise, clear explanation of the purpose of each of these and when to use them. (IntPtr, SafeHandle and HandleRef)
It looks like SafeHandle does incorporate HandleRef's KeepAlive behavior: Project Roslyn SafeHandle.cs http://referencesource.microsoft.com/#mscorlib/system/runtime/interopservices/safehandle.cs,743afbddafaea263
/*
Problems addressed by the SafeHandle class:
1) Critical finalization - ensure we never leak OS resources in SQL. Done
without running truly arbitrary & unbounded amounts of managed code.
2) Reduced graph promotion - during finalization, keep object graph small
3) GC.KeepAlive behavior - P/Invoke vs. finalizer thread ---- (HandleRef)
<...>
*/
But I'm not sure, it looks like keepalive behavior can only be acheived by providing false value to the constructor which simply marks object as not finalizable, so you have to call SafeHandle's Dispose() manualy to prevent resource leakage in that case, am I right? Can someone explain source code, what is the
private extern void InternalDispose();
private extern void InternalFinalize();
?