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);