delphi - How is Enumerator created with for in construction destroyed? -
i have collection derived tcollection, implementing getenumerator can use in construction like
for lelem in lcollection
the enumerator derived tobject, standard enumerators supplied delphi , therefor doesn't have owner.
the delphi mentions if enumerator supports idisposable disposed of, .net of course.
what wondering is, how , when , enumerator instance freed?
for each for-enum statement compiler generates code corresponds pseudocode:
enumerator := list.getenumerator; try while enumerator.movenext enumerator.current; enumerator.free; end;
the code above generated enumerators implemented class instances. if enumerator implemented interface, last line not call .free merely decrement interface reference count allowing destroyed.
Comments
Post a Comment