加入磁动力 登录
磁动力电子网-雕刻机DIY论坛,单片机论坛,CNCDIY,DIYCNC 返回首页

明浩的个人空间 http://www.cdle.net/?4 [收藏] [复制] [分享] [RSS]

日志

关于DELPHI ADO内存得不到释放的问题

已有 2808 次阅读2013-5-19 19:06 |个人分类:数据库编程| ADO, 内存

一程序使用ADO动态创建TADOQuery类,使用中发现每次open后,内存都得不到释放,无论free,close后都都到释放,N次运行后内存终会崩掉,上CSDN、GOOGLE中文都无法得到正解的解释。纠结许久,终看到一老外的ADO类的源码分析,恍然大悟。

TADOQuery = class(TCustomADODataSet)
...
constructor TCustomADODataSet.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCommand := TADOCommand.Create(Self);
...
destructor TADOQuery.Destroy;
begin
// Problem: destroy before delete of members
inherited Destroy;
FreeAndNil(FSQL);
end;
destructor TADOCommand.Destroy;
begin
// The same problem: destroy before delete of members
inherited Destroy;
Connection := nil;
FCommandObject := nil;
FreeAndNil(FParameters);
end;
See this discussion:
groups.google.ru/groups&lr=&threadm=41ed54ce%241%40newsgroups.borland.com&rnum=6&prev=/groups%3Fas_q%3DTADOCommand%26as_ugroup%3D*borland*%26as_scoring%3Dd%26lr%3D%26num%3D20%26hl%3Dru
Possible workarounds:
- don't create TADOQuery and TADOCommand dynamically (use some static
instances), "ignore small leak" on terminating of application;
- patch adodb.pas ...
AlexB.

路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)

QQ|小黑屋|手机版|Archiver|www.cdle.net 磁动力电子网 2001-2017 ( 粤ICP备10098153号

粤公网安备 44040402000001号

GMT+8, 2019-1-22 04:33

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.