我通過SAP Logon Control TLB(首次啓動時消耗大約25MB的內存!!)連接到SAP服務器,然後查詢一些數據。每個呼叫需要〜200 kB。因爲我不想每次都重新連接,所以每次需要時我都會存儲連接並將其傳遞給SAP函數對象(似乎該對象被複制,因爲此proc的成本大約爲6MB)。在完成查詢後,我釋放了該對象......但內存使用情況並未下降?因此,如果我讓程序運行了大約4個小時,我的內存已滿,電腦崩潰。Delphi/SAP函數OCX /登錄控制:內存泄漏
代碼(簡化):
connection.pas(創建連接):
SAPLogonCtrl : TSAPLogonControl;
constructor TCon.Create(usr, pswd, sys, appserv, sysnum, clnt);
begin
inherited Create;
SAPLogonCtrl := TSAPLogonControl.Create(nil);
with SAPLogonCtrl do begin
User := usr;
Password := pswd;
...
Client := clnt;
end;
FConnection := SAPLogonCtrl.NewConnection;
FConnection.Logon(0, true); //<------------- this needs ~25MB
end;
main.pas:
...
procedure TMain.Query;
var
theQuery : TSomeQuery;
begin
theQuery := TSomeQuery.Create;
theQuery.Data1 := 'something gets here';
theQuery.Data2 := 'here too';
theQuery.Call; // <------------------------ this needs about ~100kB
...
theQuery.Free; // <------------------------ nothing happens here, no mem freed!
end;
...
someQuery.pas(創建對象和呼叫查詢):
var
mySAPFunction: TSapFunctions;
mySAPQuery: Variant;
...
procedure Call;
begin
mySAPFunction := TSAPFunctions.Create;
mySAPFunction.Connection := FConnection; // <---- connection is passed (copied? costs about 5MB) from connection.pas
mySAPFunction.RemoveAll; // removes prevous added interfaces
mySAPQuery := mySAPFunction.Add('interface here');
mySAPQuery.Call;
...
// return the result
end;
我希望這是可以理解的,有人可以幫助我,因爲與此內存泄漏我的程序實際上不可用:(
在此先感謝, Eike。
東西是不正確的......你定義「myQuery:Variant」;然後使用「mySAPQuery」 – ComputerSaysNo
謝謝,編輯 –