Consider clearing state of iterator state machine when disposal completes #75666
Labels
3 - Working
Area-Compilers
Code Gen Quality
Room for improvement in the quality of the compiler's generated code
Milestone
In the example below from @stephentoub, the local
values2
in the iterator state machine holds a reference to a large allocation but the reference is kept alive past theforeach
.The
foreach
callsGetEnumerator
which may returnthis
.Then the state machine does the allocation:
That field for hoisted local
values2
never gets reset, so we hold onto the allocation for as long as the enumerablevalues
is kept around.The proposal would be for the
Dispose
method to reset all the enumerator state in the state machine once disposal completes.The text was updated successfully, but these errors were encountered: