diff --git a/src/System.Data.Jet/ComObject.cs b/src/System.Data.Jet/ComObject.cs index 6be3e97..4ab5e91 100644 --- a/src/System.Data.Jet/ComObject.cs +++ b/src/System.Data.Jet/ComObject.cs @@ -10,15 +10,12 @@ namespace System.Data.Jet { private object _instance; #if DEBUG - private readonly Guid _trackingId; + private readonly Guid _trackingId = Guid.NewGuid(); #endif public ComObject(object instance) { _instance = instance; -#if DEBUG - _trackingId = Guid.NewGuid(); -#endif } public ComObject(string progid) @@ -111,24 +108,17 @@ namespace System.Data.Jet return obj; } - private void ReleaseUnmanagedResources() + public void Dispose() { + // The RCW is a .NET object and cannot be released from the finalizer anymore, + // because it might not exist anymore. if (_instance != null) { - Marshal.FinalReleaseComObject(_instance); + Marshal.ReleaseComObject(_instance); _instance = null; } - } - public void Dispose() - { - ReleaseUnmanagedResources(); GC.SuppressFinalize(this); } - - ~ComObject() - { - ReleaseUnmanagedResources(); - } } } \ No newline at end of file