TDictionary, how to destroy it

2

I have tried every way to destroy TDictionary but whenever I have ReportMemoryLeaksOnShutdown active it always leaves something undetermined. I already tried to run the list and destroy item to item.

Code:

with foDict.GetEnumerator do
  while MoveNext do
    Current.Value.Free;

foDict.Free;

As I tried to destroy only foDict.Free;

There is both memory leakage. Anyone there have any suggestions?

    
asked by anonymous 03.11.2016 / 15:00

2 answers

0

Using your example, the code would have the following changes:

New class:

TMyCustomDictionary = TObjectDictionary<integer, TCliente>;

New use of foDict object:

foDict: TMyCustomDictionary;

New create foDict

foDict := TMyCustomDictionary.Create([doOwnsValues]);

Once this is done, the FreeList button is no longer useful

    
03.11.2016 / 20:32
0

Test as follows:

destructor TMemCorrectedDictionary.Destroy;
begin
  inherited;
  Values.Free;
  Keys.Free;
end;
  

More information here: Memory Leak in TDictionary - Problems with Workaround?

    
03.11.2016 / 15:16