Skip to content
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

Fix leak of assembly metadata instances #73945

Merged
merged 1 commit into from
Jun 11, 2024

Conversation

CyrusNajmabadi
Copy link
Member

Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1494103.

Issue introduced with #67470. In that PR i simplified code by removing several of our specialized ValueSource types. One that was used here was special in that it held onto the underlying data weakly. I failed to preserve the weak semantics with my change, leading to a leak as those assemblies changed on disk and we reloaded the assemblies.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner June 11, 2024 21:14
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 11, 2024

// Cleanup when we hit powers of two. This way we don't have to walk too often. But only when we've really
// grown. the dictionary by a substantial amount since the last time we cleaned up.
if (count == (1 << SegmentedArraySortUtils.Log2((uint)count)))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this basically preserves the prior logic we had where we'd cleanup when we hit powers-of-two capacity. i don't love this approach. But it worked before, so i'm ok rolling back to that.

@@ -48,7 +50,7 @@ internal sealed partial class VisualStudioMetadataReferenceManager : IWorkspaceS
/// <summary>
/// Access locked with <see cref="_metadataCacheLock"/>.
/// </summary>
private readonly Dictionary<FileKey, AssemblyMetadata> _metadataCache = [];
private readonly Dictionary<FileKey, WeakReference<AssemblyMetadata>> _metadataCache = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 If you want to release the metadata as soon as nothing has a strong reference, but still have the cache, you can use ReferenceCountedDisposable<AssemblyMetadata>.WeakReference here. Not required, since leveraging that would require propagating RCD throughout the locations where these values are used.

@CyrusNajmabadi CyrusNajmabadi enabled auto-merge June 11, 2024 21:37
@CyrusNajmabadi CyrusNajmabadi merged commit 05cd01d into dotnet:main Jun 11, 2024
25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jun 11, 2024
@CyrusNajmabadi CyrusNajmabadi deleted the weakAssemblyMetadata branch June 12, 2024 00:27
@jjonescz jjonescz modified the milestones: Next, 17.11 P3 Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants