diff --git a/trunk/ProcessHacker.Common/Objects/BaseObject.cs b/trunk/ProcessHacker.Common/Objects/BaseObject.cs index eea225207..dc8c04d2a 100644 --- a/trunk/ProcessHacker.Common/Objects/BaseObject.cs +++ b/trunk/ProcessHacker.Common/Objects/BaseObject.cs @@ -144,7 +144,7 @@ namespace ProcessHacker.Common.Objects // Don't need to finalize the object if it doesn't need to be disposed. if (!_owned) - GC.SuppressFinalize(this); + this.DisableFinalizer(); Interlocked.Increment(ref _createdCount); #if DEBUG @@ -161,8 +161,7 @@ namespace ProcessHacker.Common.Objects // Get rid of GC ownership if still present. this.Dispose(false); // Zero the weak reference count. - this.Dereference(_weakRefCount, false); - _weakRefCount = 0; + this.ClearWeakReferences(); } /// @@ -287,6 +286,15 @@ namespace ProcessHacker.Common.Objects get { return Thread.VolatileRead(ref _weakRefCount); } } + /// + /// Removes all weak references. + /// + private void ClearWeakReferences() + { + this.Dereference(_weakRefCount, false); + _weakRefCount = 0; + } + /// /// Disables the finalizer if it is not already disabled. /// @@ -473,6 +481,7 @@ namespace ProcessHacker.Common.Objects return 0; Thread.BeginCriticalRegion(); + _refMutex.Acquire(); try { @@ -482,6 +491,7 @@ namespace ProcessHacker.Common.Objects } finally { + _refMutex.Release(); Thread.EndCriticalRegion(); } }