Skip to content

Commit

Permalink
Merge pull request #480 from timcassell/remove-finalizers
Browse files Browse the repository at this point in the history
Remove unnecessary finalizers
  • Loading branch information
timcassell authored Oct 21, 2024
2 parents 946c1c6 + 3e22147 commit d005f36
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 117 deletions.
38 changes: 0 additions & 38 deletions Package/Core/Cancelations/Internal/CancelationInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -658,20 +658,6 @@ private sealed class CallbackNodeImpl<TCancelable> : 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<TCancelable> GetOrCreate()
{
Expand All @@ -687,10 +673,6 @@ internal static CallbackNodeImpl<TCancelable> 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;
}
Expand Down Expand Up @@ -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<TCancelable>
Expand All @@ -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()
{
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,6 @@ ConcurrentQueueSegment<T> Internal.ILinked<ConcurrentQueueSegment<T>>.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<T> GetOrCreate()
{
Expand All @@ -90,9 +78,6 @@ internal static ConcurrentQueueSegment<T> GetOrCreate(int boundedLength)

var segment = GetOrCreate();
segment._next = null;
#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE
segment._isDisposed = false;
#endif

var slots = ArrayPool<Slot>.Shared.Rent(boundedLength);
segment._slots = slots;
Expand Down Expand Up @@ -126,9 +111,6 @@ internal static ConcurrentQueueSegment<T> GetOrCreate(int boundedLength)

public void Dispose()
{
#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE
_isDisposed = true;
#endif
ArrayPool<Slot>.Shared.Return(_slots, true);
_slots = null;
Internal.ObjectPool.MaybeRepool(this);
Expand Down
18 changes: 0 additions & 18 deletions Package/Core/Linq/Internal/CountByInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }

Expand All @@ -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;
Expand Down
16 changes: 0 additions & 16 deletions Package/Core/Linq/Internal/GroupingInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ internal sealed class Grouping<TKey, TElement> : HandleablePromiseBase, IGroupin
internal TempCollectionBuilder<TElement> _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() { }

Expand All @@ -59,7 +47,6 @@ internal static Grouping<TKey, TElement> 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);
Expand Down Expand Up @@ -106,9 +93,6 @@ TElement IList<TElement>.this[int index]

public void Dispose()
{
#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE
_disposed = true;
#endif
_hashNext = null;
_nextGrouping = null;
_elements.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}
}
Expand Down
6 changes: 0 additions & 6 deletions Package/Core/Promises/Internal/MergeInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -284,9 +281,6 @@ private void Dispose()
{
ThrowIfInPool(this);
_owner = null;
#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE
_disposed = true;
#endif
ObjectPool.MaybeRepool(this);
}
}
Expand Down
1 change: 0 additions & 1 deletion Package/Core/Promises/Internal/PromiseFieldsInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
14 changes: 0 additions & 14 deletions Package/Core/Promises/Internal/PromiseInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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;
}
Expand All @@ -1959,7 +1946,6 @@ private void Dispose()
ThrowIfInPool(this);
#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE
_owner = null;
_disposed = true;
#endif
ObjectPool.MaybeRepool(this);
}
Expand Down

0 comments on commit d005f36

Please sign in to comment.