Skip to content

Fix LoaderAllocator computation for a generic type instance #279

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

Merged
merged 2 commits into from
Jan 29, 2025

Conversation

alexey-zakharov
Copy link

ClassLoader::ComputeLoaderModuleWorker uses a LoaderAllocator creation number to determine the latest LoaderAllocator to place a class in. However the method does not account the number of the type definition itself when calculating the latest number and this can lead into a situation when the generic instance is put into the older LoaderAllocator.

E.g. if we have type ClassA from AssemblyLoadContext A with number 2 and type ClassB from AssemblyLoadContext B with number 5 the resulting loader allocator for the type ClassB would correspond to AssemblyLoadContext A. If ClassB contains a static, such static would be then placed under the LoaderAllocator A, preventing AssemblyLoadContext B from unloading.

The PR updates the ComputeLoaderModuleWorker logic to account for the LoaderAllocator of a defining type, so we use it if it has the latest creation number

…r allocator of a generic type instance

(cherry picked from commit b3a73f3)
(cherry picked from commit 8aa00c8)
(cherry picked from commit 3a4e07c)
@alexey-zakharov alexey-zakharov force-pushed the fix-computeloaderallocator branch from b3a73f3 to 4e55fbb Compare January 27, 2025 19:36
@alexey-zakharov
Copy link
Author

@joncham I did run tests locally and seems like upstream tests are fine too for the change
given that this change solves our issue with ALC leak, I would like to merge it and if anything is updated upstream - I'll merge it back to our fork

@alexey-zakharov alexey-zakharov merged commit cc58bad into unity-main Jan 29, 2025
2 checks passed
@alexey-zakharov alexey-zakharov deleted the fix-computeloaderallocator branch January 29, 2025 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants