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

Expose disposing capability on IAssemblyLoaderInternal #74845

Merged
merged 5 commits into from
Aug 23, 2024

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Aug 22, 2024

Extracted from #74780 to make that PR simpler and easier to follow.

@CyrusNajmabadi CyrusNajmabadi requested review from a team as code owners August 22, 2024 02:12
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 22, 2024
@@ -11,6 +11,10 @@
using System.Reflection;
using Roslyn.Utilities;

#if NET
using System.Runtime.Loader;
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Don't think this is needed

Copy link
Member Author

Choose a reason for hiding this comment

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

technically needed since i have a <see cref="AssemblyLoadContext"/> below in teh comment. And that type (and namespace) is only available on NET not below.

_loadContextByDirectory.Clear();
}

foreach (var context in contexts)
{
context.Unload();
Copy link
Member

Choose a reason for hiding this comment

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

Note that this can throw if the AssemblyLoadContext cannot be unloaded. A misbehaving analyzer could cause this to happen by stashing references to itself somewhere you did not anticipate. That is probably somewhat rare but I also think it's going to be > 0.

This code path today doesn't really deal with exceptions because we only aggressively use it inside our unit tests. Unloading is important there because of the limitations of our test environments.

Think we should consider how we want the IDE to behave in this case and harden this code path a bit.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, worst case, unloading doesn't work, and we have some memory growth in teh case that analyzer references are changing a lot on disk. we can live with that.

@@ -51,5 +58,8 @@ public Assembly LoadFromPath(string fullPath)

return defaultLoader.LoadFromPath(fullPath);
}

public void UnloadAll()
=> defaultLoader.UnloadAll();
Copy link
Member

Choose a reason for hiding this comment

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

When UnloadAll is called do we create a new instance of this type? Keeping the existing one around likely has some issues because it's caching items like AssemblyName that you want to be different when you're live reloading.

Copy link
Member Author

Choose a reason for hiding this comment

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

When UnloadAll is called

We only call it in the finalizer of the type that owns this AnalyzerLoader. So nothing is holding onto it anymore.

do we create a new instance of this type?

Morally 'yes'. We will have thrown one away because we moved to a new one.

@CyrusNajmabadi CyrusNajmabadi changed the title Expose unloading capability on IAssemblyLoaderInternal Expose disposing capability on IAssemblyLoaderInternal Aug 22, 2024
Copy link
Member

@jaredpar jaredpar left a comment

Choose a reason for hiding this comment

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

Minor feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants