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

Dispose some pooled object instances #7330

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -68,7 +68,7 @@ public override void Initialize(AnalysisContext context)

Copy link
Member Author

Choose a reason for hiding this comment

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

Does interfaceToGenericInterfaceMapBuilder need to be Dispose()d too?

if (wellKnownTypeProvider.TryGetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCollectionsIList, out var iListType))
{
var builder = ArrayBuilder<INamedTypeSymbol>.GetInstance();
Copy link
Member

Choose a reason for hiding this comment

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

💡 The ToImmutable() line should also change to ToImmutableAndClear()

using var builder = ArrayBuilder<INamedTypeSymbol>.GetInstance();
builder.AddIfNotNull(wellKnownTypeProvider.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCollectionsGenericIList1));
builder.AddIfNotNull(wellKnownTypeProvider.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCollectionsGenericIReadOnlyList1));
if (builder.Count > 0)
Expand All @@ -79,7 +79,7 @@ public override void Initialize(AnalysisContext context)

if (wellKnownTypeProvider.TryGetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCollectionsICollection, out var iCollectionType))
{
var builder = ArrayBuilder<INamedTypeSymbol>.GetInstance();
Copy link
Member

Choose a reason for hiding this comment

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

💡 The ToImmutable() line should also change to ToImmutableAndClear()

using var builder = ArrayBuilder<INamedTypeSymbol>.GetInstance();
builder.AddIfNotNull(wellKnownTypeProvider.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCollectionsGenericICollection1));
builder.AddIfNotNull(wellKnownTypeProvider.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCollectionsGenericIReadOnlyCollection1));
if (builder.Count > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,7 @@ static void MergePlatformAttributes(ImmutableArray<AttributeData> immediateAttri
var pAttributes = parentAttributes.Platforms;
if (pAttributes != null && !pAttributes.IsEmpty)
{
var notFoundPlatforms = PooledHashSet<string>.GetInstance();
using var notFoundPlatforms = PooledHashSet<string>.GetInstance();
bool supportFound = false;
foreach (var (platform, attributes) in pAttributes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ internal ValueContentAbstractValue MergeBinaryOperation(
}

// Merge Literals
var builder = PooledHashSet<object?>.GetInstance();
using var builder = PooledHashSet<object?>.GetInstance();
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 will Dispose() on the error path (return MaybeContainsNonLiteralState) too.

foreach (var leftLiteral in LiteralValues)
{
foreach (var rightLiteral in otherState.LiteralValues)
Expand All @@ -275,7 +275,7 @@ internal ValueContentAbstractValue MergeBinaryOperation(
}
}

ImmutableHashSet<object?> mergedLiteralValues = builder.ToImmutableAndFree();
ImmutableHashSet<object?> mergedLiteralValues = builder.ToImmutable();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ImmutableHashSet<object?> mergedLiteralValues = builder.ToImmutable();
ImmutableHashSet<object?> mergedLiteralValues = builder.ToImmutableAndClear();

ValueContainsNonLiteralState mergedNonLiteralState = Merge(NonLiteralState, otherState.NonLiteralState);

return Create(mergedLiteralValues, mergedNonLiteralState);
Expand Down