-
Notifications
You must be signed in to change notification settings - Fork 5k
Added missing clearing of pooled arrays #114545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6fb2af6
ae2a649
05c8b8e
8fa44fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,7 +165,24 @@ public void Dispose() | |
if (toReturn != null) | ||
{ | ||
_arrayFromPool = null; | ||
|
||
#if SYSTEM_PRIVATE_CORELIB | ||
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>()) | ||
{ | ||
ArrayPool<T>.Shared.Return(toReturn, _pos); | ||
} | ||
else | ||
{ | ||
ArrayPool<T>.Shared.Return(toReturn); | ||
} | ||
#else | ||
if (!typeof(T).IsPrimitive) | ||
{ | ||
Array.Clear(toReturn, 0, _pos); | ||
} | ||
|
||
ArrayPool<T>.Shared.Return(toReturn); | ||
#endif | ||
} | ||
} | ||
|
||
|
@@ -200,7 +217,23 @@ private void Grow(int additionalCapacityRequired = 1) | |
_span = _arrayFromPool = array; | ||
if (toReturn != null) | ||
{ | ||
#if SYSTEM_PRIVATE_CORELIB | ||
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>()) | ||
{ | ||
ArrayPool<T>.Shared.Return(toReturn, _pos); | ||
} | ||
else | ||
{ | ||
ArrayPool<T>.Shared.Return(toReturn); | ||
} | ||
#else | ||
if (!typeof(T).IsPrimitive) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the Dispose method, the Grow method uses the !typeof(T).IsPrimitive check as a fallback. Consider adding a comment here to clarify that this condition is acceptable because T is ensured to be a primitive unmanaged type in all current contexts. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
{ | ||
Array.Clear(toReturn, 0, _pos); | ||
} | ||
|
||
ArrayPool<T>.Shared.Return(toReturn); | ||
#endif | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback check using !typeof(T).IsPrimitive may not accurately determine if T contains references for value types. Please add a clarifying comment that explains this assumption, given that in current usages T is always a primitive unmanaged type.
Copilot uses AI. Check for mistakes.