Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ private void ClearCompilationsWithAnalyzersCache()
// we basically eagarly clear the cache on some known changes
// to let CompilationWithAnalyzer go.

// we create new conditional weak table every time, it turns out
// only way to clear ConditionalWeakTable is re-creating it.
// also, conditional weak table has a leak - https://github.com/dotnet/coreclr/issues/665
// we create new conditional weak table every time netstandard as that's the only way it has to clear it.
#if NETSTANDARD
_projectCompilationsWithAnalyzers = new ConditionalWeakTable<Project, CompilationWithAnalyzers?>();
Copy link
Member Author

Choose a reason for hiding this comment

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

assigning like this means the old value gets GC'ed which runs the finalizer for the CWT. the finalizer means everything this points at gets elevated to the next generation.

#else
_projectCompilationsWithAnalyzers.Clear();
#endif
}

[Conditional("DEBUG")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ internal partial class DiagnosticIncrementalAnalyzer : IIncrementalAnalyzer
private readonly StateManager _stateManager;
private readonly InProcOrRemoteHostAnalyzerRunner _diagnosticAnalyzerRunner;
private readonly IDocumentTrackingService _documentTrackingService;

#if NETSTANDARD
private ConditionalWeakTable<Project, CompilationWithAnalyzers?> _projectCompilationsWithAnalyzers = new();
#else
private readonly ConditionalWeakTable<Project, CompilationWithAnalyzers?> _projectCompilationsWithAnalyzers = new();
#endif

internal DiagnosticAnalyzerService AnalyzerService { get; }
internal Workspace Workspace { get; }
Expand Down