From 3e22147a849b150a97bd38074a78997aa2141471 Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 20 Oct 2024 20:16:33 -0400 Subject: [PATCH] Removed unnecessary finalizers. --- .../Internal/CancelationInternal.cs | 38 ------------------- .../ConcurrentQueueSegmentInternal.cs | 18 --------- Package/Core/Linq/Internal/CountByInternal.cs | 18 --------- .../Core/Linq/Internal/GroupingInternal.cs | 16 -------- .../Internal/PromiseMergeGroupInternal.cs | 6 --- .../Core/Promises/Internal/MergeInternal.cs | 6 --- .../Internal/PromiseFieldsInternal.cs | 1 - .../Core/Promises/Internal/PromiseInternal.cs | 14 ------- 8 files changed, 117 deletions(-) diff --git a/Package/Core/Cancelations/Internal/CancelationInternal.cs b/Package/Core/Cancelations/Internal/CancelationInternal.cs index 6405b0b5..f6ee4cc0 100644 --- a/Package/Core/Cancelations/Internal/CancelationInternal.cs +++ b/Package/Core/Cancelations/Internal/CancelationInternal.cs @@ -658,20 +658,6 @@ private sealed class CallbackNodeImpl : CancelationCallbackNode, IT private CallbackNodeImpl() { } -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - private bool _disposed; - - ~CallbackNodeImpl() - { - if (!_disposed) - { - // For debugging. This should never happen. - string message = $"A {GetType()} was garbage collected without it being disposed."; - ReportRejection(new UnreleasedObjectException(message), this); - } - } -#endif - [MethodImpl(InlineOption)] private static CallbackNodeImpl GetOrCreate() { @@ -687,10 +673,6 @@ internal static CallbackNodeImpl GetOrCreate(in TCancelable cancela var node = GetOrCreate(); node._parentId = parent._smallFields._instanceId; node._cancelable = cancelable; -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - // If the CancelationRef was attached to a BCL token, it is possible this will not be disposed, so we won't check for it. - node._disposed = parent._linkedToBclToken; -#endif SetCreatedStacktrace(node, 2); return node; } @@ -719,9 +701,6 @@ internal override void Dispose() ++_nodeId; } _cancelable = default; -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - _disposed = true; -#endif ObjectPool.MaybeRepool(this); } } // class CallbackNodeImpl @@ -738,20 +717,6 @@ private sealed class LinkedCancelationNode : CancelationCallbackNodeBase, ILinke private LinkedCancelationNode() { } -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - private bool _disposed; - - ~LinkedCancelationNode() - { - if (!_disposed) - { - // For debugging. This should never happen. - string message = "A LinkedCancelationNode was garbage collected without it being disposed."; - ReportRejection(new UnreleasedObjectException(message), _target); - } - } -#endif - [MethodImpl(InlineOption)] private static LinkedCancelationNode GetOrCreate() { @@ -800,9 +765,6 @@ internal override void Dispose() [MethodImpl(InlineOption)] private void Repool() { -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - _disposed = true; -#endif ObjectPool.MaybeRepool(this); } diff --git a/Package/Core/Collections/Internal/ConcurrentQueueSegmentInternal.cs b/Package/Core/Collections/Internal/ConcurrentQueueSegmentInternal.cs index 2ca1350e..05d9def5 100644 --- a/Package/Core/Collections/Internal/ConcurrentQueueSegmentInternal.cs +++ b/Package/Core/Collections/Internal/ConcurrentQueueSegmentInternal.cs @@ -56,18 +56,6 @@ ConcurrentQueueSegment Internal.ILinked>.Next private ConcurrentQueueSegment() { } -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - private bool _isDisposed; - - ~ConcurrentQueueSegment() - { - if (!_isDisposed) - { - Internal.ReportRejection(new UnreleasedObjectException("A ConcurrentQueueSegment was garbage collected without being disposed"), null); - } - } -#endif - [MethodImpl(Internal.InlineOption)] private static ConcurrentQueueSegment GetOrCreate() { @@ -90,9 +78,6 @@ internal static ConcurrentQueueSegment GetOrCreate(int boundedLength) var segment = GetOrCreate(); segment._next = null; -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - segment._isDisposed = false; -#endif var slots = ArrayPool.Shared.Rent(boundedLength); segment._slots = slots; @@ -126,9 +111,6 @@ internal static ConcurrentQueueSegment GetOrCreate(int boundedLength) public void Dispose() { -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - _isDisposed = true; -#endif ArrayPool.Shared.Return(_slots, true); _slots = null; Internal.ObjectPool.MaybeRepool(this); diff --git a/Package/Core/Linq/Internal/CountByInternal.cs b/Package/Core/Linq/Internal/CountByInternal.cs index 628801f4..64df36f0 100644 --- a/Package/Core/Linq/Internal/CountByInternal.cs +++ b/Package/Core/Linq/Internal/CountByInternal.cs @@ -139,18 +139,6 @@ internal sealed class Node : HandleablePromiseBase, IDisposable internal TKey _key; internal TValue _value; internal int _hashCode; -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - private bool _disposed; - - ~Node() - { - if (!_disposed) - { - // For debugging. This should never happen. - ReportRejection(new UnreleasedObjectException("A PreservedEnumerationDictionary<,,>.Node was garbage collected without it being disposed."), null); - } - } -#endif private Node() { } @@ -169,17 +157,11 @@ internal static Node GetOrCreate(TKey key, int hashCode, Node hashNext) node._key = key; node._hashCode = hashCode; node._hashNext = hashNext; -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - node._disposed = false; -#endif return node; } public void Dispose() { -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - _disposed = true; -#endif _hashNext = null; _nextNode = null; _key = default; diff --git a/Package/Core/Linq/Internal/GroupingInternal.cs b/Package/Core/Linq/Internal/GroupingInternal.cs index 68ac887f..fc25f451 100644 --- a/Package/Core/Linq/Internal/GroupingInternal.cs +++ b/Package/Core/Linq/Internal/GroupingInternal.cs @@ -26,18 +26,6 @@ internal sealed class Grouping : HandleablePromiseBase, IGroupin internal TempCollectionBuilder _elements; internal TKey _key; internal int _hashCode; -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - private bool _disposed; - - ~Grouping() - { - if (!_disposed) - { - // For debugging. This should never happen. - ReportRejection(new UnreleasedObjectException("A Grouping was garbage collected without it being disposed."), null); - } - } -#endif private Grouping() { } @@ -59,7 +47,6 @@ internal static Grouping GetOrCreate(TKey key, int hashCode, Gro grouping._hashNext = hashNext; #if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE // ToLookupAsync does not dispose. GroupByAsync does. - grouping._disposed = !willBeDisposed; if (!willBeDisposed) { Discard(grouping._elements._disposedChecker); @@ -106,9 +93,6 @@ TElement IList.this[int index] public void Dispose() { -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - _disposed = true; -#endif _hashNext = null; _nextGrouping = null; _elements.Dispose(); diff --git a/Package/Core/PromiseGroups/Internal/PromiseMergeGroupInternal.cs b/Package/Core/PromiseGroups/Internal/PromiseMergeGroupInternal.cs index 170e6706..179d4bc6 100644 --- a/Package/Core/PromiseGroups/Internal/PromiseMergeGroupInternal.cs +++ b/Package/Core/PromiseGroups/Internal/PromiseMergeGroupInternal.cs @@ -61,9 +61,6 @@ private static PromisePassThroughForMergeGroup GetOrCreate() passThrough._next = target; passThrough._index = index; passThrough._owner = owner; -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - passThrough._disposed = false; -#endif return passThrough; } @@ -77,9 +74,6 @@ internal void Dispose() ThrowIfInPool(this); _owner.MaybeDispose(); _owner = null; -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - _disposed = true; -#endif ObjectPool.MaybeRepool(this); } } diff --git a/Package/Core/Promises/Internal/MergeInternal.cs b/Package/Core/Promises/Internal/MergeInternal.cs index 6c72f684..9f831df6 100644 --- a/Package/Core/Promises/Internal/MergeInternal.cs +++ b/Package/Core/Promises/Internal/MergeInternal.cs @@ -259,9 +259,6 @@ internal static PromisePassThroughForAll GetOrCreate(PromiseRefBase owner, short passThrough._index = index; passThrough._owner = owner; passThrough._id = id; -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - passThrough._disposed = false; -#endif return passThrough; } @@ -284,9 +281,6 @@ private void Dispose() { ThrowIfInPool(this); _owner = null; -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - _disposed = true; -#endif ObjectPool.MaybeRepool(this); } } diff --git a/Package/Core/Promises/Internal/PromiseFieldsInternal.cs b/Package/Core/Promises/Internal/PromiseFieldsInternal.cs index edaf136a..51b29ba4 100644 --- a/Package/Core/Promises/Internal/PromiseFieldsInternal.cs +++ b/Package/Core/Promises/Internal/PromiseFieldsInternal.cs @@ -353,7 +353,6 @@ partial class PromisePassThrough : HandleablePromiseBase protected int _index; #if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE protected PromiseRefBase _owner; - protected bool _disposed; #endif } diff --git a/Package/Core/Promises/Internal/PromiseInternal.cs b/Package/Core/Promises/Internal/PromiseInternal.cs index 67fd1955..5941c8ad 100644 --- a/Package/Core/Promises/Internal/PromiseInternal.cs +++ b/Package/Core/Promises/Internal/PromiseInternal.cs @@ -1910,18 +1910,6 @@ protected override void Execute(PromiseRefBase handler, Promise.State state, ref #endif internal partial class PromisePassThrough : HandleablePromiseBase { -#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE - ~PromisePassThrough() - { - if (!_disposed) - { - // For debugging. This should never happen. - string message = $"A {GetType()} was garbage collected without it being released. _index: {_index}, _owner: {_owner}, _next: {_next}"; - ReportRejection(new UnreleasedObjectException(message), _owner); - } - } -#endif - protected PromisePassThrough() { } [MethodImpl(InlineOption)] @@ -1941,7 +1929,6 @@ internal static PromisePassThrough GetOrCreate(PromiseRefBase owner, PromiseRefB passThrough._index = index; #if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE passThrough._owner = owner; - passThrough._disposed = false; #endif return passThrough; } @@ -1959,7 +1946,6 @@ private void Dispose() ThrowIfInPool(this); #if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE _owner = null; - _disposed = true; #endif ObjectPool.MaybeRepool(this); }