Skip to content

Conversation

@rokonec
Copy link
Member

@rokonec rokonec commented May 27, 2022

Fixes #7639

Context

Memory leak has been detected when MSBuild server runs many sessions.

Changes Made

  • Reusing BuildManager.DefaultBuildManager by not disposing it.
  • Reusing ProjectRootElementCache between MSBuild server sessions.
  • Do not clear ProjectRootElementCache before build.

Testing

Manual tests. Manual memory consumption analyze.

When I run simple console.csproj build in loop this is how used memory looked like:

Before:
image

After:
image

Notes

Changes are isolated to Server mode only.
XmlDocumentWithLocation.s_globalStringCache roots unbounded ProjectStringCache._documents which is not cleared at the end of build but at the start of build indirectly through ProjectRootElementCache callbacks, so if ProjectRootElementCache is not reused, it is never cleared.

@rokonec rokonec requested a review from AR-May May 27, 2022 10:13
Copy link
Contributor

@Forgind Forgind left a comment

Choose a reason for hiding this comment

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

Very nice; thanks for figuring this out!

@rokonec rokonec closed this May 30, 2022
@rokonec rokonec force-pushed the feature/msbuild-server branch from ad2a713 to 5ade626 Compare May 30, 2022 15:04
@rokonec rokonec reopened this May 31, 2022
Copy link
Member

@AR-May AR-May left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants