From b0542674fec3c46ba9faae0ee666dcd138af4a77 Mon Sep 17 00:00:00 2001 From: Omair Majid Date: Fri, 14 Jun 2024 12:59:11 -0400 Subject: [PATCH] Dispose some pooled object instances We Dispose()/Free() other instances of these classes, but not these specific ones. Fix that. --- .../CollectionsShouldImplementGenericInterface.cs | 4 ++-- .../InteropServices/PlatformCompatibilityAnalyzer.cs | 2 +- .../ValueContentAnalysis/ValueContentAbstractValue.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/NetAnalyzers/Core/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/CollectionsShouldImplementGenericInterface.cs b/src/NetAnalyzers/Core/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/CollectionsShouldImplementGenericInterface.cs index 0358e53113..16d613a5eb 100644 --- a/src/NetAnalyzers/Core/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/CollectionsShouldImplementGenericInterface.cs +++ b/src/NetAnalyzers/Core/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/CollectionsShouldImplementGenericInterface.cs @@ -68,7 +68,7 @@ public override void Initialize(AnalysisContext context) if (wellKnownTypeProvider.TryGetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCollectionsIList, out var iListType)) { - var builder = ArrayBuilder.GetInstance(); + using var builder = ArrayBuilder.GetInstance(); builder.AddIfNotNull(wellKnownTypeProvider.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCollectionsGenericIList1)); builder.AddIfNotNull(wellKnownTypeProvider.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCollectionsGenericIReadOnlyList1)); if (builder.Count > 0) @@ -79,7 +79,7 @@ public override void Initialize(AnalysisContext context) if (wellKnownTypeProvider.TryGetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCollectionsICollection, out var iCollectionType)) { - var builder = ArrayBuilder.GetInstance(); + using var builder = ArrayBuilder.GetInstance(); builder.AddIfNotNull(wellKnownTypeProvider.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCollectionsGenericICollection1)); builder.AddIfNotNull(wellKnownTypeProvider.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCollectionsGenericIReadOnlyCollection1)); if (builder.Count > 0) diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.cs b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.cs index 1bf6950d50..76db31bfc5 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.cs +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.cs @@ -1822,7 +1822,7 @@ static void MergePlatformAttributes(ImmutableArray immediateAttri var pAttributes = parentAttributes.Platforms; if (pAttributes != null && !pAttributes.IsEmpty) { - var notFoundPlatforms = PooledHashSet.GetInstance(); + using var notFoundPlatforms = PooledHashSet.GetInstance(); bool supportFound = false; foreach (var (platform, attributes) in pAttributes) { diff --git a/src/Utilities/FlowAnalysis/FlowAnalysis/Analysis/ValueContentAnalysis/ValueContentAbstractValue.cs b/src/Utilities/FlowAnalysis/FlowAnalysis/Analysis/ValueContentAnalysis/ValueContentAbstractValue.cs index b576646034..ba6739729e 100644 --- a/src/Utilities/FlowAnalysis/FlowAnalysis/Analysis/ValueContentAnalysis/ValueContentAbstractValue.cs +++ b/src/Utilities/FlowAnalysis/FlowAnalysis/Analysis/ValueContentAnalysis/ValueContentAbstractValue.cs @@ -261,7 +261,7 @@ internal ValueContentAbstractValue MergeBinaryOperation( } // Merge Literals - var builder = PooledHashSet.GetInstance(); + using var builder = PooledHashSet.GetInstance(); foreach (var leftLiteral in LiteralValues) { foreach (var rightLiteral in otherState.LiteralValues) @@ -275,7 +275,7 @@ internal ValueContentAbstractValue MergeBinaryOperation( } } - ImmutableHashSet mergedLiteralValues = builder.ToImmutableAndFree(); + ImmutableHashSet mergedLiteralValues = builder.ToImmutable(); ValueContainsNonLiteralState mergedNonLiteralState = Merge(NonLiteralState, otherState.NonLiteralState); return Create(mergedLiteralValues, mergedNonLiteralState);