memory leak on OraSession in multithreaded env

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Ozkan

memory leak on OraSession in multithreaded env

Post by Ozkan » Thu 29 Sep 2005 09:26

My multithreaded applications work very well but all have memory leak problems.
I wonder if there may be a memory leak problem in TOraSession?
I checked everything regarding to programming issues. but unable to find out anything produces memory leaks. I have developed the following test application, and it produces memory leak. If we comment OraSession1.Connect; line, there is no memory leak..

When the following thread function started by other routine periodically application's memory usage increases.

Code: Select all

function testThread(RMessage: Pointer): dword;
var
  OraSession1      : TOraSession;
begin
  OraSession1 := TOraSession.Create(nil);
  try
    OraSession1.ConnectPrompt := False;
    OraSession1.AutoCommit := False;
    OraSession1.ThreadSafety := True;
    OraSession1.Username := 'dbuser';
    OraSession1.Password := 'dbuserpassword';
    OraSession1.Server := 'dbinstancename';
    OraSession1.Connect;
    try
      // do something...
    finally
      OraSession1.Disconnect;
    end;
  finally
    OraSession1.Free;
  end;
  Result := 0;
end;
this thread function is started by;

Code: Select all

procedure TForm1.Timer3Timer(Sender: TObject);
var
  i                : integer;
  vThreadid        : cardinal;
  vthreadHandleArray: array[1..MAX_THREADS] of THandle;
begin
  for i := 1 to MAX_THREADS do
    vthreadHandleArray[i] := BeginThread(nil,
      0, @testThread,
      nil,
      0,
      vThreadId);
  WaitForMultipleObjects(MAX_THREADS, @vthreadHandleArray, TRUE, INFINITE);
  for i := 1 to MAX_THREADS do
    CloseHandle(vthreadHandleArray[i]);
end;
Any help please...

Ozkan

env info

Post by Ozkan » Thu 29 Sep 2005 10:56

development env:
odac 4.50.3.24
delphi 7
windows 2000 5.00.2195 Service Pack 4

oracle database env:
SunOS 5.9
Oracle8i Enterprise Edition Release 8.1.7.2.0

Ozkan

help

Post by Ozkan » Mon 03 Oct 2005 06:48

Any help will be appreciated.
thank you.

Alex
Posts: 655
Joined: Mon 08 Nov 2004 08:39

Post by Alex » Mon 03 Oct 2005 08:08

Having debugged your test program we saw that function WaitForMultipleObjects doesn't wait for all threads to terminate as it should do. When time interval is less then threads lifetime we have the increasing count of threads. As result the amount of memory used by application increases. We have corrected your test program and could not find any memory leaks.

Ozkan

Post by Ozkan » Mon 03 Oct 2005 12:02

thank you for your response.
firstly would you please post corrections you did?

due to my tests; with using timer, neither thread/event count nor handle count increases.
when I set timer interval to high values, there is no increase in handle or thread counts.. also i noticed that WaitForMultipleObjects always waits for all threads termination.

i have developed a new thread starts testThread thread to replace timer due to your When time interval is less then threads lifetime note. With using this starter thread instead of timer, neither thread count nor handle count increases, but memory usage increases again...

Code: Select all

function starterThread(RMessage: Pointer): integer;
var
  i                : integer;
  vThreadid        : cardinal;
  vthreadHandleArray: array[1..MAX_THREADS] of THandle;
begin
  while processStatus do
    begin
      DebugMsg(DateTimeToStr(now) + ' starting test threads...');
      for i := 1 to MAX_THREADS do
        vthreadHandleArray[i] := BeginThread(nil,
          0, @testThread,
          nil,
          0,
          vThreadId);
      DebugMsg(DateTimeToStr(now) + ' wait for test threads finish...');
      WaitForMultipleObjects(MAX_THREADS, @vthreadHandleArray, TRUE, INFINITE);
      DebugMsg(DateTimeToStr(now) + ' test threads finished');
      for i := 1 to MAX_THREADS do
        CloseHandle(vthreadHandleArray[i]);
      DebugMsg(DateTimeToStr(now) + ' closed test threads handles...');
      WaitForSingleObject(hServerStopped, 10000);
    end;
  Result := 0;
end;
this new thread starts testThread threads and then waits for all started testThread threads termination and closes their handles, sleeps 10 secs and restarts testThread threads again.. so there should be no lifetime problem...

and the last test;
there is no thread just a session component on form with two buttons: connect and disconnect.
connect button calls session component's connect method and disconnect button calls session component's disconnect method. with every connect&disconnect memory usage increases...

Alex
Posts: 655
Joined: Mon 08 Nov 2004 08:39

Post by Alex » Wed 05 Oct 2005 06:54

You are right about WaitForMultipleObjects function - we have troubles with it because of exceeding MAX_OBJECTS limit, but we still couldn't detect any memory leaks - please specify the way you detect them.

Post Reply