Memory leak assigning query parameters lazarus / 16-Databases ---------------------------------------------------------------------- luca · 2014-02-26 11:10 Hi. I activated check for memory leaks (-gh) from project options. I ran the program and when I closed it I received a lot of mem-leaks. By checking memory address I discovered the problem in assigning string value to query parameter: If I use Code: [Select] query1.paramByName('ID').Value = 'SomeID' I have memory leak. If I use Code: [Select] query1.paramByName('ID').AsString= 'SomeID' No memory leaks appear. I'm using Lazarus v1.1 FPC2.7.1 32 bit for Windows Regards. Luca ---------------------------------------------------------------------- exdatis · 2014-02-26 11:37 Which database? ---------------------------------------------------------------------- exdatis · 2014-02-26 11:40 Also, if you want, can we see sql statement? ---------------------------------------------------------------------- luca · 2014-02-26 11:42 I'm using TSQLQuery with ODBC connection to MSSQL. Regards. Luca ---------------------------------------------------------------------- exdatis · 2014-02-26 13:12 I have no experience with M$Sql, but for many years I use PostgreSQL and Firebird without problem and with very complex queries and many parameters. As usual I have a few hundred tables and millions of records in my db. ---------------------------------------------------------------------- BigChimp · 2014-02-26 13:27 Perhaps a good idea to write a minimal FPC program that demonstrates the problem, including the DDL needed for creating the db: http://wiki.lazarus.freepascal.org/Database_bug_reporting#FreePascal and attach it. This can be used for others to verify the problem (as an attachment to a forum post or as an attachment a bug report). If you raise a bug report, please include th program as well so the problem can be verified and if it is fixed, the fix can be verified as well. IIRC, there were some problems with variants in FPC trunk, but I don't know whether these still influence parameter binding See related bug: http://bugs.freepascal.org/view.php?id=24728 BTW: IIRC, using .Value involves a conversion to variant and from variant to the actual db datatype. This is a relatively costly operation and you're much better off directly using the .As... properties as shown in your second line of code. ---------------------------------------------------------------------- luca · 2014-02-26 14:23 Many thanks BigChimp I think you're right! Looking into assembler debug, memory leak is into SYSTEM_$$_assign$SHORTSTRING$$VARIANT function. In any case, as you suggested, I'll change all .value with .asString. Regards. Luca