mmleak TDictionary<TKey, TValue>.TOrderedEnumerable vs TContainedIterator

Issue #179 resolved
Daniel Razny created an issue

For my understanding:

Contained objects get destroyed by their parent/controller.

TOrderedEnumerable in the dictionary just don't want that the parent is destroyed, because it holds a not reference counted pointer to it.

procedure Test;
var
  X: IDictionary<string, string>;
  L: TPair<string, string>;
begin
  X := TCollections.CreateDictionary<string, string>; // Inc ref counter to X => 1

  X.AddOrSetValue('1','42');
  X.AddOrSetValue('3','42');
  X.AddOrSetValue('9','42');

  for L in X.Ordered do // Inc ref counter to X => 2
    ShowMessage(l.Key);
  // Dec ref counter to X => 1
end; // Dec ref counter to X => 0 
// Ordered is still alive => mm leak 

This could be a bug in TDictionary<TKey, TValue>.TKeyCollection, TDictionary<TKey, TValue>.TValueCollection and TMultiMapBase

My dirty hot fixe for the TOrderedEnumerable:

Comments (3)

  1. Log in to comment