TDictionary<string, string> - Memory Leaks

Since updating recently to SDK version 9.4.198.1377 we have experienced a persistent memory leak in our Delphi application which becomes apparent when terminating the application.

I have tracked part of the leak (I believe) to a global object (a dictionary) created in uROTypes which is freed during finalization but whose members are not freed.

The object in question is declared on uROTypes line 329:

329    gComplexType_Attributes: TDictionary<TROComplexTypeClass,TDictionary<String, String>>;

It is then instantiated on uROTypes line 1897 (initialization block):

1897    gComplexType_Attributes := TDictionary<TROComplexTypeClass,TDictionary<String, String>>.Create;

During the course of running the application, keys (each a class of TROComplexType) are added to the dictionary, each with a corresponding value which is a TDictionary<string, string> object. These TDictionary objects are the ones which are not freed.

Finalization begins on uROTypes line 1908 and the dictionary is freed on line uROTypes line 1910:

1910    gComplexType_Attributes.Free;

As gComplexType_Attributes does not own its values, they are not freed and each is recorded as a memory leak.

Replacing the TDictionary with a TObjectDictionary with an appropriate ownership parameter seems to (partially) resolve the issue.

1897      gComplexType_Attributes := TObjectDictionary<TROComplexTypeClass,TDictionary<String, String>>.Create([doOwnsValues]);

In fact this prevents precisely 50% of the leaks (where there were 48, now there are 24, etc). Presumably there is a related process somewhere which I have not yet been able to track down?

Thanks, logged as bugs://81105

bugs://81105 got closed with status fixed.

do the same changes in uROExceptions.pas