Skip to content

Destroy all generic instances when module is unloaded #286

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

Conversation

alexey-zakharov
Copy link

@alexey-zakharov alexey-zakharov commented Mar 28, 2025

ClassUnloadStarted and ClassUnloadFinished profiler api callbacks are not called for generic instances which are allocated under a different loader allocator. That:

The suggested change makes Destruct to be called for all classes.
There is a potential sideeffect as EEClass:Destruct when the class is a delegate type - https://github.com/dotnet/runtime/blob/main/src/coreclr/vm/class.cpp#L124, but if I read the code correctly it should decrement a reference that was added when a delegate instance was created.

@alexey-zakharov alexey-zakharov marked this pull request as ready for review March 28, 2025 10:23
@alexey-zakharov alexey-zakharov requested a review from joncham March 28, 2025 10:24
@UnityAlex
Copy link
Collaborator

Is this a change that upstream would be interested in?

@alexey-zakharov
Copy link
Author

Is this a change that upstream would be interested in?

I believe so, I'll make an issue to discuss it

Copy link
Member

@joncham joncham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, but really deferring to upstream issue discussion and resolution.

@alexey-zakharov
Copy link
Author

created an upstream issue with a reproproject - dotnet#114068

@alexey-zakharov alexey-zakharov force-pushed the fix-classunload-callback-for-generic-instances branch from e4d3ed3 to f1969bc Compare April 1, 2025 15:29
alexey-zakharov and others added 5 commits April 3, 2025 20:28
Co-authored-by: Noah Falk <noahfalk@users.noreply.github.com>
(cherry picked from commit 97ee0de)
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
(cherry picked from commit 20233ec)
@alexey-zakharov alexey-zakharov force-pushed the fix-classunload-callback-for-generic-instances branch from f1969bc to dd1a231 Compare April 3, 2025 18:29
@alexey-zakharov
Copy link
Author

@UnityAlex @joncham the PR should now match dotnet#114107 which is merged to upstream

Copy link
Collaborator

@UnityAlex UnityAlex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for upstreaming this!

@alexey-zakharov alexey-zakharov merged commit e79ac34 into unity-main Apr 4, 2025
2 checks passed
@alexey-zakharov alexey-zakharov deleted the fix-classunload-callback-for-generic-instances branch April 4, 2025 11:22
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.

3 participants