Memory leak in Delphi XE8 and 10 Seattle
Posted: Tue 10 Nov 2015 07:20
We have come across a problem in the recent versions of Delphi, XE8 and 10 Seattle, that there is a memory leak reported when we exit our application. We have raised this with Embarcadero, but I am posting here also in case anyone can help, or at least say that they have had the same problem also?
The leak can be reproduced with a very simple two line program:
SQLQuery1.SQL.Add('SELECT columns.table_name, columns.column_name FROM information_schema.columns'
+ ' WHERE columns.table_schema = ''public'' ORDER BY columns.table_name, columns.column_name;');
SQLQuery1.Active := true;
Adding this simple block of code to a FormCreate, for a form with TSQLQuery and TSQLConnection objects with properties set up so that a connection to a database is successful, gives a memory leak (as reported by EurekaLog). Here is an excerpt from the call stack:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|Methods |Details|Stack |Address |Module |Offset |Unit |Class |Procedure/Method |Line |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|+Leak #1: Type=Data at $0700AE40; Total size=512; Count=1 |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|00000002|04 |00000000|0083CA20|Project4.exe|0043CA20|Data.DBXDynalink |TDBXDynalinkDriverCommonLoader|LoadDriverLibraryAndMethodTable |873[24] |
|00000002|04 |00000000|0083C6CF|Project4.exe|0043C6CF|Data.DBXDynalink |TDBXDynalinkDriver |LoadDriver |769[5] |
|00000002|04 |00000000|0083F46C|Project4.exe|0043F46C|Data.DBXDynalinkNative |TDBXDynalinkDriverNative |CreateConnection |87[1] |
|00000002|04 |00000000|0078D8EB|Project4.exe|0038D8EB|Data.DBXCommon |TDBXConnectionFactory |GetConnection |6661[12] |
|00000002|04 |00000000|0078D801|Project4.exe|0038D801|Data.DBXCommon |TDBXConnectionFactory |GetConnection |6640[0] |
|00000002|04 |00000000|007183E5|Project4.exe|003183E5|Data.DB |TCustomConnection |SetConnected |3567[8] |
|00000002|04 |00000000|00829241|Project4.exe|00429241|Data.SqlExpr |TCustomSQLDataSet |OpenCursor |4066[2] |
|00000002|04 |00000000|0072BC91|Project4.exe|0032BC91|Data.DB |TDataSet |SetActive |12470[12] |
|00000002|04 |00000000|00868C68|Project4.exe|00468C68|Unit6 |TForm6 |FormCreate |35[6] |
|00000002|04 |00000000|006C6295|Project4.exe|002C6295|Vcl.Forms |TCustomForm |DoCreate |3758[3] |
|00000002|04 |00000000|006C5EB5|Project4.exe|002C5EB5|Vcl.Forms |TCustomForm |AfterConstruction |3642[1] |
|00000002|04 |00000000|006C5E65|Project4.exe|002C5E65|Vcl.Forms |TCustomForm |Create |3632[35] |
|00000002|04 |00000000|006D0DEA|Project4.exe|002D0DEA|Vcl.Forms |TApplication |CreateForm |10557[13] |
|00000002|04 |00000000|008755D5|Project4.exe|004755D5|Project4 | |Initialization |23[3] |
|00000002|03 |00000000|76F17BFC|kernel32.dll|00017BFC|KERNEL32 | |BaseThreadInitThunk | |
|00000002|03 |00000000|7769AD1D|ntdll.dll |0005AD1D|ntdll | | (possible RtlInitializeExceptionChain+141)| |
|00000002|03 |00000000|7769ACE5|ntdll.dll |0005ACE5|ntdll | | (possible RtlInitializeExceptionChain+85) | |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
We are not suggesting that the Devart DBExpress PostgreSQL driver is leaking memory - it appears that we have simply uncovered a memory leak in Embarcadero's source code used in XE8 and 10 Seattle. Running the same exact code in XE7 does not give the leak (and we have tried using the last few versions of the Devart DBExpress PostgreSQL driver i.e. all combinations of driver version and Delphi version, and regardless of what driver version we use, the leak only occurs in XE8 and 10 Seattle, and never in XE7).
If anyone can shed any insight into this issue it would be much appreciated!
The leak can be reproduced with a very simple two line program:
SQLQuery1.SQL.Add('SELECT columns.table_name, columns.column_name FROM information_schema.columns'
+ ' WHERE columns.table_schema = ''public'' ORDER BY columns.table_name, columns.column_name;');
SQLQuery1.Active := true;
Adding this simple block of code to a FormCreate, for a form with TSQLQuery and TSQLConnection objects with properties set up so that a connection to a database is successful, gives a memory leak (as reported by EurekaLog). Here is an excerpt from the call stack:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|Methods |Details|Stack |Address |Module |Offset |Unit |Class |Procedure/Method |Line |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|+Leak #1: Type=Data at $0700AE40; Total size=512; Count=1 |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|00000002|04 |00000000|0083CA20|Project4.exe|0043CA20|Data.DBXDynalink |TDBXDynalinkDriverCommonLoader|LoadDriverLibraryAndMethodTable |873[24] |
|00000002|04 |00000000|0083C6CF|Project4.exe|0043C6CF|Data.DBXDynalink |TDBXDynalinkDriver |LoadDriver |769[5] |
|00000002|04 |00000000|0083F46C|Project4.exe|0043F46C|Data.DBXDynalinkNative |TDBXDynalinkDriverNative |CreateConnection |87[1] |
|00000002|04 |00000000|0078D8EB|Project4.exe|0038D8EB|Data.DBXCommon |TDBXConnectionFactory |GetConnection |6661[12] |
|00000002|04 |00000000|0078D801|Project4.exe|0038D801|Data.DBXCommon |TDBXConnectionFactory |GetConnection |6640[0] |
|00000002|04 |00000000|007183E5|Project4.exe|003183E5|Data.DB |TCustomConnection |SetConnected |3567[8] |
|00000002|04 |00000000|00829241|Project4.exe|00429241|Data.SqlExpr |TCustomSQLDataSet |OpenCursor |4066[2] |
|00000002|04 |00000000|0072BC91|Project4.exe|0032BC91|Data.DB |TDataSet |SetActive |12470[12] |
|00000002|04 |00000000|00868C68|Project4.exe|00468C68|Unit6 |TForm6 |FormCreate |35[6] |
|00000002|04 |00000000|006C6295|Project4.exe|002C6295|Vcl.Forms |TCustomForm |DoCreate |3758[3] |
|00000002|04 |00000000|006C5EB5|Project4.exe|002C5EB5|Vcl.Forms |TCustomForm |AfterConstruction |3642[1] |
|00000002|04 |00000000|006C5E65|Project4.exe|002C5E65|Vcl.Forms |TCustomForm |Create |3632[35] |
|00000002|04 |00000000|006D0DEA|Project4.exe|002D0DEA|Vcl.Forms |TApplication |CreateForm |10557[13] |
|00000002|04 |00000000|008755D5|Project4.exe|004755D5|Project4 | |Initialization |23[3] |
|00000002|03 |00000000|76F17BFC|kernel32.dll|00017BFC|KERNEL32 | |BaseThreadInitThunk | |
|00000002|03 |00000000|7769AD1D|ntdll.dll |0005AD1D|ntdll | | (possible RtlInitializeExceptionChain+141)| |
|00000002|03 |00000000|7769ACE5|ntdll.dll |0005ACE5|ntdll | | (possible RtlInitializeExceptionChain+85) | |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
We are not suggesting that the Devart DBExpress PostgreSQL driver is leaking memory - it appears that we have simply uncovered a memory leak in Embarcadero's source code used in XE8 and 10 Seattle. Running the same exact code in XE7 does not give the leak (and we have tried using the last few versions of the Devart DBExpress PostgreSQL driver i.e. all combinations of driver version and Delphi version, and regardless of what driver version we use, the leak only occurs in XE8 and 10 Seattle, and never in XE7).
If anyone can shed any insight into this issue it would be much appreciated!