在定时器中执行以下代码, 出现内存泄漏, try
adoquery1 := Tadoquery.Create(nil);
adoquery1.Connection := adoconnection1;
SQLStr := Format(cSQLStr,[TestCode,nDelay]);
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(SQLStr);
ADOQuery1.Open; finally
ADOQuery1.free; //从任务管理器中看,内存没有回收,偶尔会回收一点
end;
adoquery1 := Tadoquery.Create(nil);
adoquery1.Connection := adoconnection1;
SQLStr := Format(cSQLStr,[TestCode,nDelay]);
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(SQLStr);
ADOQuery1.Open; finally
ADOQuery1.free; //从任务管理器中看,内存没有回收,偶尔会回收一点
end;
改成以下试试
adoquery1 := Tadoquery.Create(nil);
adoquery1.Connection := adoconnection1;
SQLStr := Format(cSQLStr,[TestCode,nDelay]);
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(SQLStr);
try
ADOQuery1.Open;
finally
ADOQuery1.free; //从任务管理器中看,内存没有回收,偶尔会回收一点
end;
还用了iNum := iNum + ADOQuery1.FieldList[0].AsInteger才到finally的
会不会有关系
还是那样
cSQLStr = ' select Count(*) from GWCallBill where ProcFlag = 0'
+ ' and task_id in ( select task_id from taskinfo where Test_Code=%d and Delete_Flag=0 )'
+ ' and calltype=0 and (sysdate-record_date)*86400>%d';
这里看不出什么问题,另外Free之前的Close可以不用,Destroy里自己知道去Close