Repository navigation
fix: release removed and cleared slots on netstandard builds [patch] - #103
Merged
Merged
Conversation
On netstandard2.0/2.1 the slot-clearing guard fell back to !typeof(T).IsValueType, which is false for every struct, including ones that hold references. ContiguousMap stores a struct Entry, so it never released a removed or cleared key or value there, and ContiguousCollection, ContiguousSet and RingBuffer leaked for struct elements such as KeyValuePair<int, object>. The decision now lives in SlotClearing.IsNeeded<T>(): it uses RuntimeHelpers.IsReferenceOrContainsReferences<T>() wherever the API exists (netstandard2.1, netcoreapp2.0 and later) and always clears on netstandard2.0. Fixes #79 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NfxXtpcxX8hkLYrePfHkV4
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #79
What was wrong
On the netstandard2.0 and netstandard2.1 builds, the slot-clearing guard fell back to
!typeof(T).IsValueType. That check is false for every struct, including structs that hold references:ContiguousMapstores a structEntry, so on those builds it never released a removed or cleared key or value.ContiguousCollection,ContiguousSetandRingBufferleaked struct elements such asKeyValuePair<int, object>or(string, int).Change
SlotClearing.IsNeeded<T>():RuntimeHelpers.IsReferenceOrContainsReferences<T>()wherever that API exists (netstandard2.1, netcoreapp2.0 and later).ContiguousMapRemove/Clear,ContiguousCollectionRemoveAt/Clear,ContiguousSetRemove/Clear, andRingBuffer.Clear. The#if NET5_0_OR_GREATERblocks and their conditionalusinglines are gone.Tests
New file:
Containers.Test/SlotClearingTests.cs.ContiguousMap.Clear, after removing every key from aContiguousMap, and afterClear/RemoveAton aContiguousCollection<KeyValuePair<int, object>>andClearon aContiguousSet<KeyValuePair<int, object>>.IsNeededtests: true forobject,KeyValuePair<int, object>and(string, int), and false forint.Containers_DoNotDecideSlotClearingWithAValueTypeCheck: a source guard that fails if any container goes back to anIsValueTypecheck.Manual netstandard2.0 check (the issue's acceptance criteria allow this when CI has no netstandard leg). I referenced the built
netstandard2.0/ktsu.Containers.dllfrom a net10 console app and checked with aWeakReferenceafterGC.Collect:ContiguousMap<int, object>.Clear()ContiguousMap<int, object>.Remove(key)ContiguousCollection<KeyValuePair<int, object>>.Clear()Full suite: 431 tests passed (
dotnet test).There is no overlap with the open RingBuffer PRs #99 and #100. They change
PushBackand enumeration, notClear.🤖 Generated with Claude Code
https://claude.ai/code/session_01NfxXtpcxX8hkLYrePfHkV4
Generated by Claude Code