We help IT Professionals succeed at work.
Get Started

ADO Memory leak with DELPHI 2007

790 Views
Last Modified: 2016-01-21
Hi,

I have a simple process with ADOquery running on a timer event, but I keep losing memory, memory keep increasing, in about 12 hours increased from 35MB to 75MB

The code
Type
  TNotifyPolicy = record
    ID: String;
    Title: String;
    EmpID: String;
    EmpName: String;
    DeptName: String;
    DeptID: String;
    OrgID: String;
    OrgName: String;
    Email: String;
    ReportedTo: String;
    DeptEmail: String;
    ShowBeginLate: Boolean;
    ShowOutEarly: Boolean;
    ShowGap: Boolean;
    ShowAbsentTime: Boolean;
    ShowAbsent: Boolean;
    ShowMissPunch: Boolean;
    ShowErrorPunch: Boolean;
    ShowContAbsent: Boolean;
    AbsentCntToNotify: Integer; 
    CAResetOnOffDay: Boolean; 
    SendEmail: Boolean;
    SendEndOfShift: Boolean;
    SendFrom: String;
    SendTo: String;
    SendCC: String;
    SendBCC: String;
    EmailSubject: String;
    EmailMsgText: String;
    SMTP: String;
    SMTPPORT: Integer;
    SMTPTYPE: Integer;
    SMTPUSERID: String;
    SMTPPWD: String;
    TranslateTXT: String;
  end;
 
Function TemxNotify.GetNotifyPolicy(EmpID: String): TNotifyPolicy;
begin
  try
    try
      {get notify policy for employee}
      qryNotifyPolicy.Close;
      qryNotifyPolicy.SQL.Text := Format('SELECT * FROM VEMPNOTIFYLST WHERE NPEMID = ''%s''', [EmpID]);
      qryNotifyPolicy.Open;

      {if not found get default notify policy}
      if qryNotifyPolicy.IsEmpty then begin
        qryNotifyPolicy.Close;
        qryNotifyPolicy.SQL.Text := Format('select NOTIFYPOLICY.*, REPEMPFILE.*  from NOTIFYPOLICY , REPEMPFILE ' +
                                           'where NOTIFYPOLICY.NPISDEFAULT=1 and REPEMPFILE.emid = ''%s''', [EmpID]);
        qryNotifyPolicy.Open;
      end;

      if qryNotifyPolicy.RecordCount > 0 then begin
        if not qryNotifyPolicy.FieldByName('NPID').IsNull then begin
          With Result do begin
            ID := qryNotifyPolicy.FieldByName('NPID').AsString;
            EmpID := EmpID;
            EmpName := qryNotifyPolicy.FieldByName('EMNAME').AsString;
            DeptName := qryNotifyPolicy.FieldByName('DMNAME').AsString;
            DeptID := qryNotifyPolicy.FieldByName('DMID').AsString;
            OrgID := qryNotifyPolicy.FieldByName('OCID').AsString;
            OrgName := qryNotifyPolicy.FieldByName('OCNAME').AsString;
            Email := qryNotifyPolicy.FieldByName('EMEMAIL').AsString;
            ReportedTo := qryNotifyPolicy.FieldByName('EMREPORTEDTO').AsString;
            DeptEmail := qryNotifyPolicy.FieldByName('DMEMAIL').AsString;
            Title := qryNotifyPolicy.FieldByName('NPTITLE').AsString;
            ShowBeginLate := qryNotifyPolicy.FieldByName('SHOWBEGINLATE').AsInteger = 1;
            ShowOutEarly := qryNotifyPolicy.FieldByName('SHOWOUTEARLY').AsInteger = 1;
            ShowGap := qryNotifyPolicy.FieldByName('SHOWGAP').AsInteger = 1;
            ShowAbsentTime := qryNotifyPolicy.FieldByName('SHOWABSENTTIME').AsInteger = 1;
            ShowAbsent := qryNotifyPolicy.FieldByName('SHOWABSENT').AsInteger = 1;
            ShowMissPunch := qryNotifyPolicy.FieldByName('SHOWMISSPUNCH').AsInteger = 1;
            ShowErrorPunch := qryNotifyPolicy.FieldByName('SHOWERRORPUNCH').AsInteger = 1;
            ShowContAbsent := qryNotifyPolicy.FieldByName('SHOWCONTABSENT').AsInteger = 1;
            AbsentCntToNotify := qryNotifyPolicy.FieldByName('ABSENTCNTTONOTIFY').AsInteger;
            CAResetOnOffDay := qryNotifyPolicy.FieldByName('CARESETONOFFDAY').AsInteger = 1;
            SendEmail := qryNotifyPolicy.FieldByName('SENDEMAIL').AsInteger = 1;
            SendEndOfShift := qryNotifyPolicy.FieldByName('SENDENDOFSHIFT').AsInteger = 1;
            SendFrom := qryNotifyPolicy.FieldByName('SENDFROM').AsString;
            SendTo := qryNotifyPolicy.FieldByName('SENDTO').AsString;
            SendCC := qryNotifyPolicy.FieldByName('SENDCC').AsString;
            SendBCC := qryNotifyPolicy.FieldByName('SENDBCC').AsString;
            EmailSubject := qryNotifyPolicy.FieldByName('EMAILSUBJECT').AsString;
            EmailMsgText := qryNotifyPolicy.FieldByName('EMAILMSGTEXT').AsString;
            {SMTP := qryNotifyPolicy.FieldByName('NPSMTP').AsString;
            SMTPPORT := qryNotifyPolicy.FieldByName('NPSMTPPORT').AsInteger;
            SMTPTYPE := qryNotifyPolicy.FieldByName('NPSMTPTYPE').AsInteger;
            SMTPUSERID := qryNotifyPolicy.FieldByName('NPSMTPUSERID').AsString;
            SMTPPWD := qryNotifyPolicy.FieldByName('NPSMTPPWD').AsString;}
            TranslateTXT := qryNotifyPolicy.FieldByName('NPTRANSLATE').AsString;
          end;
        end else Result.ID := '-1';
      end else Result.ID := '-1';
    except
      on E: Exception do begin
        LogError('GetNotifyPolicy: ' + E.Message);
      end;
    end;
  finally
    qryNotifyPolicy.Close;
  end;
end;

Function ProcessData
var
  NotifyPolicy: TNotifyPolicy;
begin
try
    qryEmpList.Close;    
    qryEmpList.SQL.Text := 'SELECT DISTINCT EAMEMID from EMPATTNMST where (EAMCALCSTATUS = 1) AND ' +
                           'NOT (EAMEMID IN (SELECT EMID FROM VSRVCEMPLIST)) order by EAMEMID';
    qryEmpList.DisableControls;
    qryEmpList.Open;
    
    while not qryEmpList.EOF and not (StopLoop) do begin
      qryATTMST.Close;
      qryATTMST.DisableControls;
      qryATTMST.SQL.Text := 'SELECT * FROM EMPATTNMST WHERE (EAMEMID = :EAMEMID) AND (EAMDATE <= :EAMDATE) ' +
	 		    'AND (EAMATTNSTATUS <> :EAMATTNSTATUS) AND ' +
	  		    '(EAMCALCSTATUS = 1) ORDER BY EAMEMID, EAMDATE';
      qryATTMST.Parameters.ParamByName('EAMDATE').DataType := ftDateTime;
      qryATTMST.Parameters.ParamByName('EAMATTNSTATUS').DataType := ftFloat;
      qryATTMST.Parameters.ParamByName('EAMEMID').DataType := ftString;

      qryATTMST.Parameters.ParamByName('EAMDATE').Value := DateOf(prmToDate);
      qryATTMST.Parameters.ParamByName('EAMATTNSTATUS').Value := 99;
      qryATTMST.Parameters.ParamByName('EAMEMID').Value := prmEMID;
      qryATTMST.Open;
    
      NotifyPolicy := GetNotifyPolicy(EMID);
    
      qryEmpList.Next
    end;
    
Finally
  qryEmpList.Close;
  qryATTMST.Close;
End;
end;

Open in new window

This function run from the timer event every 1 minute
I am using Delphi 2007
Backbend Database Oracle 12g
Oracle client it is ODAC 12g
Project type Windows service

Note: when I comment this line "NotifyPolicy := GetNotifyPolicy(EMID);", the leak decrease too much
Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
Unlock 1 Answer and 36 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE