Open AArnott opened 5 months ago
@AArnott +1 to this feature. Maybe you can tell me if the following situation below is related...
SomeProducer
, and implementation of IProducer
that every DLL can use)SomeProducer
(treated as IProducer
everywhere necessary) as a proxy.Attached is a small toy example of the situation (zip of a 7z, sorry). load_context_demo.zip
Related: https://github.com/JamesNK/Newtonsoft.Json/issues/2253 https://github.com/dotnet/runtime/issues/13283
@jacob-vincent-mink, no, that's not the issue at hand here. This issue isn't about being able to unload assemblies. It's about being able to recover memory in the GC heap occupied by the proxy and maybe even drop the I/O connection itself when the proxy is dropped from all accessibility to the program.
An assembly is not expected to be unloadable after it has been used in RPC, because serializers tend to statically store information about types in that assembly as a perf optimization. There are APIs (at least in .NET 8) that allow us to store information in such a way that it would be discarded when an assembly is unloaded, but that isn't used consistently throughout the stack. I expect it would be a significant effort to achieve what you're describing. If you want that feature, please file a separate issue to track it. I don't expect we'll prioritize it anytime soon though, just to set expectations.
We might be able to allow finalization to recover leaked memory by:
Note this is just a best-effort mitigation. The documentation should still emphasize the importance of disposing proxies.