Alternative to GC.Collect to free memory after calling AssemblyLoadContext.Unload #46579
Replies: 1 comment 3 replies
-
In terms of file handles, I think it might be related to In general the case of frequently loading and unloading contexts might not have been considered when the runtime is optimized. If there are too many small, separate tasks, which requires small assemblies (for example, dynamically generated assemblies), it might be better to consider executing them in new processes. And for the most important question, I don't think there is any alternatives to Also note that |
Beta Was this translation helpful? Give feedback.
-
A bit of reference in this issue here: #44679
We've now got the problem that rapidly loaded and unloaded AssemblyLoadContexts associated with a high volume of actions in our app leads to spikes in memory usage before the GC can clear it.
I understand it's not good to second guess the GC here - but we've added a full blocking collection following each call to Unload, the difference is a flat 300mb v.s. spiking upto around 2gb.
Normally I would not say this is a problem, but we're running this app in a containerised/kubernetes environment and it's causing problems:
Any advice?
Edit: Actually - there are no resource.limit set for the pod; after setting it the GC does respect it. I do have one worry some clever person might be able to address though:
When the GC collects the Assemblies that have been released by the AssemblyLoadContext after calling Unload, not only does this release the memory associated but also some file handles - does the GC also free stuff based on file handle pressure? We've had issues with "Too many open files" so it troubles me - although so long as it tracks the memory pressure maybe the file handle limit is a "higher ceiling" 🤔
Beta Was this translation helpful? Give feedback.
All reactions