Fix UnitTestRunner leaking some test class instances #5715
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #5711
TestMethodInfo
holds_classInstance
. So storing it in a dictionary that lives for the whole test session will leak the stored test class instances.While I think we could avoid storing
_classInstance
inTestMethodInfo
, it's still an "overkill" to storeTestMethodInfo
in the dictionary as we end up only accessing eitherTestClassInfo
orTestAssemblyInfo
.So, the dictionary is now split to two dictionaries, one that stores class fixtures and the other stores assembly fixtures. This in theory is still bad because as the number of test classes grow, this dictionary can grow, and also this dictionary is only ever used when
ConsiderFixturesAsSpecialTests
is enabled, but we still always create the dictionary. But this is a step forward as it at least avoids rooting test class instances.