...
Query: TSQLQuery
...
Query.SQL.Clear;
Query.SQL.Add('INSERT INTO pumps'#13#10 +
'VALUES (NULL, :title, :power)');
Query.ParamByName('title').AsString:= title;
Query.ParamByName('power').AsFloat:= power;
try
Query.ExecSQL;
except
on E: Exception do
begin
ShowMessage(E.Message);
end;
end;
查询通过 driver=Sqlite 链接到 SQLConnection。所有操作都有效,但是当我尝试将非唯一值插入具有唯一索引的列时,我得到关于值存在的异常。好的,我的代码捕获它并显示一条消息“列标题不是唯一的”,但在调试器向我显示该异常 TWICE 之前。当我关闭程序时,内存管理器会告诉内存泄漏,泄漏是:
- 21 - 28 字节:UnicodeString x 4
- 61 - 68 字节:TDBXSqliteCommand x2
- 69 - 76 字节:TDBXMorphicCommand x 2
- 221 - 236 字节:未知 x 2
有可能避免这种情况吗?
UPD:我使用 FastMM4 来获取详细的日志,下面是关于一次内存泄漏的部分:
A memory block has been leaked. The size is: 68
This block was allocated by thread 0xB18, and the stack trace (return addresses) at the time was:
4068A6 [System.pas][System][@GetMem$qqri][4203]
4082BB [System.pas][System][TObject.NewInstance$qqrv][14969]
4089D2 [System.pas][System][@ClassCreate$qqrpvzc][16231]
7D5A91 [Data.DbxSqlite.pas][Data.DbxSqlite][Dbxsqlite.TDBXSqliteCommand.$bctr$qqrp26Data.Dbxcommon.TDBXContextp35Data.Dbxsqlite.TDBXSqliteConnection][567]
6E3DFE [Data.DBXCommon][Generics.Collections.%TDictionary__2$20System.UnicodeStringp32Data.Dbxcommon.TDBXCreateCommand%.GetBucketIndex$qqrx20System.UnicodeStringi]
7D4C8E [Data.DbxSqlite.pas][Data.DbxSqlite][Dbxsqlite.TDBXSqliteDriver.CreateSqliteCommand$qqrp26Data.Dbxcommon.TDBXContextp29Data.Dbxcommon.TDBXConnectionp26Data.Dbxcommon.TDBXCommand][295]
6CE4DA [Data.DBXCommon.pas][Data.DBXCommon][Dbxcommon.TDBXDriver.CreateMorphCommand$qqrp26Data.Dbxcommon.TDBXContextp29Data.Dbxcommon.TDBXConnectionp26Data.Dbxcommon.TDBXCommand][7569]
6D5177 [Data.DBXCommon.pas][Data.DBXCommon][Dbxcommon.TDBXDelegateDriver.CreateMorphCommand$qqrp26Data.Dbxcommon.TDBXContextp29Data.Dbxcommon.TDBXConnectionp26Data.Dbxcommon.TDBXCommand][11061]
6D09F4 [Data.DBXCommon.pas][Data.DBXCommon][Dbxcommon.TDBXConnection.CreateMorphCommand$qqrp26Data.Dbxcommon.TDBXCommand][8480]
6D1C21 [Data.DBXCommon.pas][Data.DBXCommon][Dbxcommon.TDBXMorphicCommand.DerivedOpen$qqrv][9084]
6D1974 [Data.DBXCommon.pas][Data.DBXCommon][Dbxcommon.TDBXCommand.Open$qqrv][8962]
The block is currently used for an object of class: TDBXSqliteCommand