Page 1 of 1

Memory consumption of TUniQuery with Oracle database connection

Posted: Thu 13 Sep 2018 10:26
by ChrisHe
I am repeatedly executing a SQL Statement via TUniQuery to a connected Oracle database.

Each execution of the query raises memory consumption of the application.
The memory only gets freed on application close.

In the following example the memory consumption raises from approximately 3.5 MB to 26 MB.

Though if i am connecting to SQL Server or MySQL, the memory gets released after each destruction of TUniQuery.

I am using UniDAC 7.3.9. for RAD Studio 10.2.3.

Sample code:

Code: Select all

uses
  Uni,
  Winapi.PsAPI;

procedure TfrmUniQueryTest.btnOracleQueryClick(Sender: TObject);

  function CurrentProcessMemory(): Cardinal;
  var
    MemCounters: TProcessMemoryCounters;
  begin
    Result := 0;
    MemCounters.cb := SizeOf(MemCounters);
    if GetProcessMemoryInfo(GetCurrentProcess, @MemCounters, SizeOf(MemCounters)) then
      Result := MemCounters.WorkingSetSize
    else
      RaiseLastOSError;
  end;

var
  DBConnection: TUniConnection;
  DBQuery: TUniQuery;
  idx: Integer;
  memBegin, memEnd: Cardinal;
begin
  lbMemory.Clear();

  DBConnection := TUniConnection.Create(nil);
  try
    DBConnection.Server := 'DBServer';
    DBConnection.Username := 'USR';
    DBConnection.Password := 'PWD';
    DBConnection.ProviderName := 'Oracle';

    DBConnection.Connect();

    memBegin := CurrentProcessMemory();

    for idx := 0 to 5000 do
    begin

      DBQuery := TUniQuery.Create(nil);
      try
        DBQuery.Connection := DBConnection;
        DBQuery.SQL.Text := 'select 1 from dual;';
        DBQuery.Open();
        DBQuery.Close();
      finally
        DBQuery.Free();
      end;

    end;

    memEnd := CurrentProcessMemory();

    lbMemory.Items.Add(memBegin.ToString());
    lbMemory.Items.Add(memEnd.ToString());

  finally
    DBConnection.Free();
  end;
end;

Re: Memory consumption of TUniQuery with Oracle database connection

Posted: Thu 13 Sep 2018 13:36
by MaximG
Thank you for the information. We will investigate the described issue and let you know the results shortly.

Re: Memory consumption of TUniQuery with Oracle database connection

Posted: Fri 14 Sep 2018 12:33
by MaximG
We fixed the bug with memory leak when executing queries that end with the ";" character. The fix will be included in the next build of our product, which we are planning to release next week. As a workaround, do not use the ";" character at the end of the query

Re: Memory consumption of TUniQuery with Oracle database connection

Posted: Mon 17 Sep 2018 04:29
by ChrisHe
Thank you for your effort. The workaround also works fine and we can use this solution for now.

Re: Memory consumption of TUniQuery with Oracle database connection

Posted: Tue 18 Sep 2018 13:06
by MaximG
The fix was included in the new build of ODAC 10.2.7 (18-Sep-2018). You can upgrade to this version of ODAC by downloading and installing the necessary distribution in Customer Portal at https://secure.devart.com