-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix leak of assembly metadata instances #73945
Conversation
|
||
// 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))) |
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.
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 = []; |
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.
💡 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.
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.