SortedDictionary appears to not honor doOwnsValues
Issue #411
resolved
Using:
Result := TCollections.CreateSortedDictionary<String, TMyObj>(TStringComparer.OrdinalIgnoreCase, [doOwnsValues]);
and the value objects are not freed.
While using:
Result := TCollections.CreateDictionary<String, TMyObj>(TStringComparer.OrdinalIgnoreCase, [doOwnsValues]);
Does correctly free values.
Comments (5)
-
repo owner -
repo owner - changed status to open
-
reporter It does appear that removing items will destroy the objects. But if you don’t remove them and just let the dictionary go out of scope they don’t appear to clear.
begin var dict := TCollections.CreateSortedDictionary<String, TObject>(TStringComparer.OrdinalIgnoreCase, [doOwnsValues]); dict.Add('foo', TMyObj.Create); end.
This appears to report that TMyObj is leaked. Apologies about the version, I pulled the latest changes just in case it was fixed before I reported and wasn’t sure exactly what version to pick.
-
reporter Also Dict.Clear doesn’t seem to free the objects (I assume that’s the same issue as going out of scope.)
-
repo owner - changed status to resolved
fixed
#411→ <<cset 1c3b52d7ae38>>
- Log in to comment
I cannot repro - also you did not specify a version.
In 2.0 and latest develop this prints ‘destroy’: