delphi - 关于使用 TIdTcpServer 的 FDQuery
问题描述
如何防止 TFDQuery 在使用 TIdTcpServer 运行的应用程序中导致过多的内存消耗?
我在运行时创建 TFDQuery,使用后我在 TIdTcpServer 的 OnExecute 事件上将其销毁:
Query := TFDQuery.Create(Cn);
Query.Connection := Cn;
Query.SQL.Text := 'update table set column = 0 where ip = :ip';
Query.Params.ParamByName('ip').Value := ip;
Query.ExecSQL;
FreeAndNil(Query);
每个新连接都在 MSSQL 上执行选择/插入/更新,所以我总是创建/销毁对象,但内存仍在增加(我正在与在 TcpServer 上创建各种连接的客户端进行测试)
我已经测试过了,如果我从 OnExecute 应用程序内存中删除 TFDQuery 在测试中总是可以的。
cn
是始终处于活动状态并在应用程序启动时创建并在应用程序关闭时销毁的 TFDConnection。
解决方案
在运行时使用这种创建/销毁方法解决:
with TFDQuery.Create(nil) do
begin
try
Connection := Cn;
SQL.Text := 'update table set column = 0 where ip = :ip';
Params.ParamByName('ip').Value := ip;
ExecSQL;
finally
Free;
end;
end;
推荐阅读
- docker - docker-compose 无法运行容器
- ssl - SSPI Schannel API 返回 0xAE06 或 CALG_ECDH_EPHEM 的未记录值
- azure - 如何设置我的 Linux Azure VM 以便我可以通过浏览器进行连接?
- python - 为什么 Python 不能同时打印“read()”和“read().splitlines()”?
- php - 对于可写挂载,php is_writable 总是返回 false
- django - 扩展应用模板时出现 TemplateDoesNotExist 错误
- validation - What is Bootstrap 4 Form Validation novalidate for?
- python - keep elements of an np.ndarray by values of another np.array (vectorized)
- javascript - 如何使用内部对象附加对象值
- postgresql - How to implement change detection on a postgres table in order to NOTIFY a nestjs backend