public static void FreeComObject <T>(ref T obj) where T : class { #if false // When debug -> use special version, that writes debug information ComDebug.DebugFreeComObject(ref obj); #else // take it to local variable var localObj = Interlocked.Exchange(ref obj, null); // if it is already null -> return if (localObj == null) { return; } if (Marshal.IsComObject(localObj)) // Is real COM? Not CLR object? { if (IsMono && Xpcom.InvokeRequired) { _comGC.Free(ref localObj); } else { Marshal.ReleaseComObject(localObj); } } #endif }
internal static void FreeComObject <T>(ref T obj) where T : class { #if false // When debug -> use special version, that writes debug information ComDebug.DebugFreeComObject(ref obj); #else // take it to local variable var localObj = Interlocked.Exchange(ref obj, null); // if it is already null -> return if (localObj == null) { return; } Marshal.ReleaseComObject(localObj); #endif }