-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
SDK Resolver assemblies leak AssemblyLoadContexts #6842
Comments
One possible fix would be to make the |
@marcin-krystianc Yes, I think that would do the trick. It looks like the other uses are in statics: msbuild/src/Shared/TypeLoader.cs Line 24 in f566ba1
Are you interested in sending a PR to fix this? |
Done in #6864 |
Awesome, thank you! |
We want to use static for CoreClrAssemblyLoader so each unique SDK resolver assembly is loaded into memory and JITted only once. Fixes #6842 (comment) ### Context We use static for the `CoreClrAssemblyLoader` field so each unique SDK resolver assembly is loaded into memory and JITted only once. All subsequent load requests will return assembly from the assembly loader's cache instead of loading it again from disk. This change increases the performance of SDK resolution and at the same time avoids leaking memory due to loading the same SDK resolver assembly multiple times and never unloading it. ### Changes Made The `CoreClrAssemblyLoader` field in the `SdkResolverLoader` class was changed from non-static to static member. The same instance of `CoreClrAssemblyLoader` will be used by all instances of `SdkResolverLoader`. It is consistent now with other uses of `CoreClrAssemblyLoader` in msbuild. ### Testing Tested manually using repro from #5037 (comment) ### Notes Alternative approach would be to use collectible `CoreClrAssemblyLoader` / `AssemblyLoadContext` - that would fix the leak as well but it would be less performant as it wouldn't benefit from re-using already loaded and JITed assemblies.
The SDK resolver loader should cache by assembly path much like the task loader does, and evidently does not today:
Originally posted by @marcin-krystianc in #5037 (comment)
The text was updated successfully, but these errors were encountered: