- edited description
TList<T> deallocates if you use "For X in ..."
Issue #325
invalid
The list enumerator will keep a reference to the list while looping through the list, but if the list is not already referenced through an interface, once the enumerator is deallocated, the entire list will also deallocate.
Sample code that reproduces behaiviour:
uses System.SysUtils, Spring.Collections.Lists; var vList: TList<Integer>; i,j: integer; procedure DeAllocatesList(AList: TList<Integer>); var i: Integer; begin for i in AList do begin // Do nothing ... or something, doesn't matter, the list is destroyed end; end; begin vList := TList<Integer>.Create; DeAllocatesList(vList); vList.Add(1); // This statement fails end.
Perhaps the enumerator could check if the list was already referenced before increasing refcount
Comments (2)
-
reporter -
repo owner - changed status to invalid
Spring4D collections must exclusively used as interfaces.
- Log in to comment