Skip to content

Avoid ConcurrentDictionary allocation in DisposeObjectsBeforeLosingScope#50309

Closed
Alex-Sob wants to merge 3 commits intodotnet:mainfrom
Alex-Sob:dev/alex-sob/avoid-concurrentdictionary-allocation
Closed

Avoid ConcurrentDictionary allocation in DisposeObjectsBeforeLosingScope#50309
Alex-Sob wants to merge 3 commits intodotnet:mainfrom
Alex-Sob:dev/alex-sob/avoid-concurrentdictionary-allocation

Conversation

@Alex-Sob
Copy link
Copy Markdown

Description

Currently DisposeObjectsBeforeLosingScope analyzer always allocates a ConcurrentDictionary<K, V> when it's initialized. As it's used to avoid reporting duplicate diagnostics for the same location, it's only needed when there are rule violations in code.

Suggested improvement

Defer dictionary allocation until it's actually needed in the case when rule violations are detected. This should avoid the allocation for successful builds.

Testing

All unit tests for this analyzer passed.

This PR has already been reviewed by @stephentoub (the original was created in the wrong repo)

@Alex-Sob Alex-Sob requested a review from a team as a code owner August 17, 2025 09:49
@Alex-Sob
Copy link
Copy Markdown
Author

Alex-Sob commented Aug 22, 2025

Hello @stephentoub! This is a PR that has been reviewed by you the other day (I re-created PR submitted by mistake to the old repo). Also I would like to contribute the following PRs with analyzer fixes and performance improvements:

#50397
#50339
#50411
#50310
#50367

Is it possible to get these PRs reviewed? Thank you!

@github-actions
Copy link
Copy Markdown
Contributor

Due to lack of recent activity, this PR has been labeled as 'Stale'. It will be closed if no further activity occurs within 7 more days. Any new comment will remove the label.

@github-actions github-actions Bot added the stale label Mar 21, 2026
@github-actions github-actions Bot closed this Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants