Memory consumption of TUniQuery with Oracle database connection

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ChrisHe
Posts: 2
Joined: Thu 13 Sep 2018 09:51

Memory consumption of TUniQuery with Oracle database connection

Post by ChrisHe » Thu 13 Sep 2018 10:26

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;

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Memory consumption of TUniQuery with Oracle database connection

Post by MaximG » Thu 13 Sep 2018 13:36

Thank you for the information. We will investigate the described issue and let you know the results shortly.

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Memory consumption of TUniQuery with Oracle database connection

Post by MaximG » Fri 14 Sep 2018 12:33

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

ChrisHe
Posts: 2
Joined: Thu 13 Sep 2018 09:51

Re: Memory consumption of TUniQuery with Oracle database connection

Post by ChrisHe » Mon 17 Sep 2018 04:29

Thank you for your effort. The workaround also works fine and we can use this solution for now.

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Memory consumption of TUniQuery with Oracle database connection

Post by MaximG » Tue 18 Sep 2018 13:06

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

Post Reply