Description
ClassUnloadStarted and ClassUnloadFinished profiler api callbacks are not called for generic instances which are allocated under a different than defining module loader allocator. That:
The if (pMT->IsCanonicalMethodTable()) check in Module::FreeClassTables method prevents the callback from being called.
Reproduction Steps
The following project demonstrates the issue
ClassUnloadRepro.zip
Expected behavior
Console output is
ClassUnloadStarted: TestLibrary.DummyType, TestLibrary.dll
ClassUnloadStarted: List<TestLibrary.DummyType>
ClassLoadFinished calls: 907
ClassUnloadStarted calls: 2
Actual behavior
Console output is
ClassUnloadStarted: TestLibrary.DummyType, TestLibrary.dll
ClassLoadFinished calls: 907
ClassUnloadStarted calls: 1
Regression?
No response
Known Workarounds
N/A
Configuration
.NET 8, 9, 10
Windows x64
Other information
Unity-Technologies#286 solves the issue but may introduce sideeffects on delegate code dereferencing - perhaps it would be better to split profiler callbacks from the other logic in EEClass::Destruct method