-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
How to release collectable assembly (cannot null belonging type)? #10149
Comments
I'm creating dynamic assemblies too but they are never collected...
Indeed the @JiriCepelkaFirstLineSoftware did you solved this issue or is it a bug from .NET Core? I saw that a class AssemblyLoadContext exists however, it is not possible to create a dynamic assembly elsewhere that in the current AppDomain if I understand correctly? So it's not possible to unload our dynamic assembly... |
@GrabYourPitchforks @steveharter Can either one of you answer these questions? |
Sorry missing notifications from this repro. It works better if an actual issue is created in https://github.com/dotnet/runtime/issues. This issue is discussed in dotnet/runtime#29842 For @Adriien-M's example, I verified it works if build in Release mode and a loop is added: for (int i = 0; i < 10; i++)
{
GC.Collect();
GC.WaitForPendingFinalizers();
Console.WriteLine($"{i} type = { weak.Target}");
} |
@JiriCepelkaFirstLineSoftware I ran your example on .NET Framework 4.7.2 and it did not hit the if (assem.GetName().Name == collectibleOne)
{
throw new Exception("Found!");
} Closing this; please log an issue in https://github.com/dotnet/runtime/issues or add to dotnet/runtime#29842 |
The documentation states
To do so I have prepared some methods:
It could be said it works. At least until there is created type by TypeBuilder. This is because of no setters available on Type and no option to null backing fields (reflection does not find them).
If you uncomment the code you will get exception. No option to get backing fields with no option to set props without setters mean the type cannot be nulled so it will retain some references to assembly that could not be collected.
My questions:
• Am I wrong?
• If so how to achieve this?
• Is the documentation wrong?
• If so how the collectable assembly can be collected?
If you are in doubt you can try to comment out foreachs calling the NullAllValues. You will get exception too.
There is also post about this on Software Engineering.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: