Open NMSAzulX opened 3 years ago
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
I don't understand what you're asking for. If you're talking about unloading app domains, then .Net Core/.Net 5+ has only one, so it doesn't make sense to unload that. If you want to unload an assembly, you can use AssemblyLoadContext
for that. Have you looked into that?
@svick i think what they're asking is an API to force free ("GC") an object that is otherwise being kept alive by being subscribed to event handlers (on AppDomain
specifically).
If you're asking for a way to forcibly GC an object, can you explain why exactly do you need that and why other alternative approaches are not sufficient?
@Suchiman In that case, I would ask: Why can't you unsubscribe that handler? If it's because code that you need and can't modify does something that you don't want, then I would suggest the usual .Net approach for that kind of situation: use reflection.
Strongly listening static event is a common pattern of managed memory leak. In this case they should be adjusted to use weak event pattern.
@svick Yes, I aready use ALC long long ago.
@NMSAzulX the code to hack this with reflection would look something like
var pExit = typeof(AppContext).GetField(nameof(AppContext.ProcessExit), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
var del = ((Delegate)pExit?.GetValue(null))?.GetInvocationList().FirstOrDefault(x => x.Method.Name == "EnsureClearingPools");
if (del != null)
{
AppContext.ProcessExit -= (EventHandler)del;
}
and then the same again for DomainUnload
@Suchiman Thank you! And https://github.com/dotnet/aspnetcore/issues/21906 to asp.net core.
Tagging subscribers to this area: @dotnet/gc See info in area-owners.md if you want to be subscribed.
Author: | NMSAzulX |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-GC-coreclr`, `untriaged` |
Milestone: | - |
changing the label to VM - it would be up to the VM to remove references to objects if it wants objects to be considered reclaimable by the GC (without causing any functional problems).
Is this issue already being processed?
@Maoni0 How's the progress? :)
I think you mean @mangod9
Background and Motivation
I have encountered some thorny situations that cannot be uninstalled:
Can the official provide a method that allows an object to be marked if it is referenced? When GC occurs, the object is forcibly recycled. (remove reference). Or forcibly empty the memory where it is located.
Proposed API
Usage Examples
Alternative Designs
Risks