delphi - Is it necessary to manage the lifetimes of TEnumerators from generic containers? -
if call getenumerator
method of generics.collections
object, need explicitly free enumerator when i'm done it?
yes need free enumerator. whoever calls getenumerator
owns returns.
when for/in
loop compiler writes code , ensures enumerator object disposed of. when call it, job dispose of enumerator.
this in fact easy question answer yourself. create program calls getenumerator
, fails free
it. use memory manager's facilities check whether or not object leaked.
uses system.generics.collections; begin reportmemoryleaksonshutdown := true; tlist<integer>.create begin getenumerator; free; end; end.
and results in following leak report:
an unexpected memory leak has occurred. unexpected small block leaks are:
- 13 - 20 bytes: tlist.tenumerator x 1
Comments
Post a Comment