RDP1974 40 Posted July 25, 2022 hi, do you know if https://docwiki.embarcadero.com/Libraries/Sydney/en/System.Generics.Collections.TDictionary.Remove remove method will dispose an inserted record automatically? Share this post Link to post
Rollo62 536 Posted July 25, 2022 The TObjectDictionary supports ownerships Share this post Link to post
RDP1974 40 Posted July 25, 2022 I was wondering about use a record instead of a class or a object if add will call a mem place for the record of maybe if we should use New and Dispose on remove probably is better stay with a basic class creation and disposal the doc is unclear, if remove dispose the loaded struct or should be done manually Share this post Link to post
PeterBelow 238 Posted July 25, 2022 3 hours ago, RDP1974 said: hi, do you know if https://docwiki.embarcadero.com/Libraries/Sydney/en/System.Generics.Collections.TDictionary.Remove remove method will dispose an inserted record automatically? Records are value types, so adding a record to a TDictionary<recordtype> adds a copy of the record to the internal storage, and Remove then clears up that copies memory. So there are no leaks, but adding a record and getting it back later always makes a full copy of the record, which can be a bit hard on performance. 2 Share this post Link to post
David Heffernan 2345 Posted July 25, 2022 Are you holding records or pointers to records? Because the question only makes sense if the latter. If the latter then something needs to allocate and deallocate. But i suspect that you are doing the former. Share this post Link to post