You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In addition to that, the presence of static value caches ( like https://github.com/dahomey-technologies/Dahomey.Json/blob/master/src/Dahomey.Json/Util/Default.cs ) leads to any assembly cached by said classes that isn't in the same loadcontext to also become permanently loaded, as this cache is never pruned and it keeps strong references to Type objects (and instances from the assembly) which causes the assembly to become non-unloadable (this only happens if Dahomey.Json and the target assembly are in different contexts)
Setup/reproduction steps:
Create a sample host app.
Create a class library that uses Dahomey.Json anyhow (calling .SetupExtensions() on JsonSerializerOptions & (de)serializing something once is enough)
Load the class library into its own AssemblyLoadContext.
Load Dahomey.Json into any unloadable context.
Call .SetupExtensions() on a JsonSerializerOptions object, then (de)serialize anything from the calling assembly.
Result:
The calling assembly now has cached values in Dahomey.Json's static caches, meaning it's being held loaded by Dahomey.Json.
Dahomey.Json now has the AsyncLocal static initialised, leading to it being mapped for all threads active in the app, further meaning it's being held loaded by async pinned handles & strong handles from internal thread AsyncLocalValueMaps. Neither of the assemblies will ever unload
If further information (or a reproduction app) is required, please let me know.
The text was updated successfully, but these errors were encountered:
Hey, sincere apologies for the delay on responding to this, I'm currently recreating the reproduction app (as I lost it during a system reinstall) and I'll get back to you soon on whether or not that fixes it 👍
Short description: The use of asynclocals in
https://github.com/dahomey-technologies/Dahomey.Json/blob/master/src/Dahomey.Json/Serialization/SerializationContext.cs#L8
causes the runtime to put an instance of this variable on every thread's asynclocalmap, as seen through inspecting gc roots of each loaderallocator:
This in turn causes the types from Dahomey.Json to remain loaded on all thread stacks indefinitely, leading to the assembly not being unloadable.
In addition to that, the presence of static value caches ( like https://github.com/dahomey-technologies/Dahomey.Json/blob/master/src/Dahomey.Json/Util/Default.cs ) leads to any assembly cached by said classes that isn't in the same loadcontext to also become permanently loaded, as this cache is never pruned and it keeps strong references to Type objects (and instances from the assembly) which causes the assembly to become non-unloadable (this only happens if Dahomey.Json and the target assembly are in different contexts)
Setup/reproduction steps:
Result:
Neither of the assemblies will ever unload
If further information (or a reproduction app) is required, please let me know.
The text was updated successfully, but these errors were encountered: