Memory Leak Problem

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Alexliuyong
Posts: 3
Joined: Thu 22 Jan 2015 02:08

Memory Leak Problem

Post by Alexliuyong » Thu 22 Jan 2015 02:23

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!

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Memory Leak Problem

Post by AlexP » Thu 22 Jan 2015 07:48

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.

Alexliuyong
Posts: 3
Joined: Thu 22 Jan 2015 02:08

Re: Memory Leak Problem

Post by Alexliuyong » Fri 23 Jan 2015 01:37

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.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Memory Leak Problem

Post by AlexP » Mon 26 Jan 2015 07:53

Please try to reproduce the problem on the latest ODAC version http://www.devart.com/odac/download.html and let us know the result.

Alexliuyong
Posts: 3
Joined: Thu 22 Jan 2015 02:08

Re: Memory Leak Problem

Post by Alexliuyong » Tue 27 Jan 2015 00:48

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.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Memory Leak Problem

Post by AlexP » Tue 27 Jan 2015 10:10

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.

gicla
Posts: 2
Joined: Wed 11 Mar 2015 17:02

Re: Memory Leak Problem

Post by gicla » Wed 11 Mar 2015 17:20

I just created a test project with ODAC Trial and I'm experiencing exactly the same behaviour.

Regards
Claudio

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Memory Leak Problem

Post by AlexP » Thu 12 Mar 2015 05:42

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.

Post Reply