-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[API Proposal]: Let ALC unload by String Name #111197
Comments
This is not actionable at all. The name of ALC is only informative. It's not unique, nor tracked by runtime.
The
You don't really need to call runtime/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs Lines 114 to 126 in fba5430
|
@huoyaoyuan thanks for your reply, but in dynamic scenarios like hot swappable plugins or dynamic razor views, unloading an assembly is required manually (in case of a razor view GC can collect it too if its not in use). So for most user it may not be necessary, but these advance cases require assembly unload on demand as well as keep the collectible:true process. i am aware that collectible assemblies are collected when all references to it are removed, but in above cases we need to do both sometimes, if we are hot swapping we initiate assembly unload and wait and load newer version and a named ALC can make this process smoother. hope my use-case scenario is more clear now. |
Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov |
There's not a concept of "manual unloading" or "on demand". The
You don't need to name an ALC either. Just create a new one and throw away the old one.
This proposal is not actionable. The above are explaining why it won't achieve any business purpose. |
You can implement this method yourself if you really need it:
It is exactly what the runtime implementation would look like. As @huoyaoyuan explained, it is probably not what you want to do. |
@huoyaoyuan @jkotas thanks for the explanation, i am clear about the functionality now although this makes plugin hot swapping a bit tedious, I hope this can improve in future implementations. Also, from docs, this intent was not so clear, my understanding was once unload was called, assembly was marked for sweeping and all weaker references would go away when calling it, guess it's not the case. |
You have to track something either way, be it a string or an ALC instance. You can track only the ALC and get its name from the If you want to |
Background and motivation
Hello Team Dotnet,
i want to know if this is feasible to add as feature in dotnet to provide a mechanism in to unload an AssemblyLoadContext (ALC) by specifying its friendly string name (as originally passed to the constructor) without the need to keep a direct reference to the AssemblyLoadContext instance.
as we can do this
var alc = new AssemblyLoadContext("ALC_Key", isCollectible: true);
we would like to have a similar method like
AssemblyLoadContext.UnloadByName("ALC_Key")
. The intent behind this is if alc is stilll loaded it goes into unloading and we dont have to keep alc reference for the same. which is not good if we are marking isCollectible: true as that makes it strongly referenced, defeating the purpose of future unloading of non-used objects.so, i am thinking something along this can be implemented:
This proposed API would simplify usage of collectible AssemblyLoadContexts in scenarios where the user only tracks them by a friendly name. It reduces code complexity and eliminates the need for the user to maintain references to the ALC for the sole purpose of calling Unload().
Thank you for considering this proposal!
API Proposal
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: