Page 1 of 1

Memory Leak Problem

Posted: Thu 22 Jan 2015 02:23
by Alexliuyong
I encountered memory leak problem when using odac9.3.8 edition in multithread application. My development environment: Win7 64bit, DelphiXE2, Oracel 10g,using Direct Mode.
When Run the following code in a thread, I found in taskmanage the memory enlarged.
while true do
begin
sleep(1000);
OraSession1.connect;
OraSession1.Disconnect;
end;
Who can give me the solution,Thanks very much!

Re: Memory Leak Problem

Posted: Thu 22 Jan 2015 07:48
by AlexP
Hello,

We cannot reproduce the described problem. Please try reproducing the problem on the latest ODAC version 9.4.14. Please try running the following code and let us know the results.

Code: Select all

program Project9;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils, ora, Classes;

type
  TMyThread = class(TThread)
  private
    OraSession: TOraSession;
  public
    constructor Create;
    procedure execute; override;
  end;

{ TMyThread }

constructor TMyThread.Create;
begin
  inherited create(true);

  OraSession := TOraSession.Create(nil);
  OraSession.Options.Direct := True;
  OraSession.ConnectString := 'scott/tiger@localhost:1521:orcl';
end;

procedure TMyThread.execute;
begin
  while true do begin
    Sleep(1000);
    OraSession.Connect;
    OraSession.Disconnect;
  end;
end;

var
  MyThread: TMyThread;
begin
  MyThread := TMyThread.Create;
  try
    MyThread.Execute;
    while MyThread.Started do;

  finally
    MyThread.Free;
  end;
end.

Re: Memory Leak Problem

Posted: Fri 23 Jan 2015 01:37
by Alexliuyong
At first, thanks for AlexP's reply.
I did ran the code, but still found in taskmanager the memory size enlarged about 4k every 30s-50s. This time I still used odac9.3.8. That's so strange. Maybe I should use the latest odac edition.

Re: Memory Leak Problem

Posted: Mon 26 Jan 2015 07:53
by AlexP
Please try to reproduce the problem on the latest ODAC version http://www.devart.com/odac/download.html and let us know the result.

Re: Memory Leak Problem

Posted: Tue 27 Jan 2015 00:48
by Alexliuyong
I used the latest edition odac9.4.14, run the code supplied. This time I found the phenomenon was different. In about 3 minutes, memory enlarged 4k, decreased 24k, then increased 24k, again enlarged 4k. This procedure appeared over and over. The final result is memory increased but more slowly.

Re: Memory Leak Problem

Posted: Tue 27 Jan 2015 10:10
by AlexP
We have reproduced the described case and will investigate the reason for such behavior. We will inform you as soon as we have any results.

Re: Memory Leak Problem

Posted: Wed 11 Mar 2015 17:20
by gicla
I just created a test project with ODAC Trial and I'm experiencing exactly the same behaviour.

Regards
Claudio

Re: Memory Leak Problem

Posted: Thu 12 Mar 2015 05:42
by AlexP
We have investigated this behaviour more deeply, and this behavior is most probably due to the Delphi memory manager. The example below demonstrates a small memory increase at constant freeing of memory:

Code: Select all

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils, math, Forms;

var
  p1, p2: pointer;
  i, j: integer;
begin
  Randomize;
  while True do begin
    try
      i := Random(1000000);
      j := Random(1000000);
      GetMem(p1, i);
      GetMem(p2, j);
    finally
      FreeMem(p1);
      FreeMem(p2);
      sleep(500);
    end;
  end;
end.