Board index » delphi » Client leaks memory when using COM server

Client leaks memory when using COM server

Hi all!

I have created a standalone, single instance, COM server using
the Delphi wizard. Every time I create an interface to it in my
client application, the client application leaks 4k of memory.
This can be observed in the Win 2000 task manager.

I've tested the same thing using a demo application that ships
with Delphi 7, and the problem is there too.

To me it seems, that you really can not use a single instance
COM server from a Delphi program, without loosing memory!

The simple example code below is enough to make the error
occur. When the code is in a timer event, like below, the
memory leak is easily seen in the task manager (the timer
itself has nothing to do with the error).

Has anyone seen this problem? Is there a solution to it?

procedure TForm1.Timer1Timer(Sender: TObject);
var
  MyIntf: IPemacServerIntf;
  a, b: Integer;
begin
  MyIntf := CoPemacServerIntf.Create;
  MyIntf.Connect(a, b);
end;

 

Re:Client leaks memory when using COM server


Now, I could be wrong, but this sounds very similar to a problem which can happen using delphi for certain kinds of ISAPI dlls.

I can remember where I read it, but the essence of the problem someone found is that whenever the web server called the DLL, another 4k was added to the usage, which wasn't freed whenthe call/process finished.

Their investigation turned out that they used a function which was dependant on the forms unit, and each fresh use of it created another instance of the application global, without releasing any previous instance, resulting in a 4k mem usage. This is something that is deep in the bowels of the vcl, and I can't remember which call they used which call did it.

Their solution was to ditch ISAPI, and use a CGI exe, which tho was more clunky, meant that all memory was freed when the exe finshed.

This might be your prob! I have done a quick search [www.google.com with delphi isapi leak] to try and find the original article, it threw up:

http://codecentral.borland.com/codecentral/ccweb.exe/listing?id=18735 [Download didn't work for me tho]

basically look at all the function calls, and see if any of them might use the forms unit. If so, there is you answer - try rewriting that function youself to circumvent the problem..

HTH
Duncan

Quote
"Matz" <matz.ostl...@prevas.se> wrote:

>Hi all!

>I have created a standalone, single instance, COM server using
>the Delphi wizard. Every time I create an interface to it in my
>client application, the client application leaks 4k of memory.
>This can be observed in the Win 2000 task manager.

>I've tested the same thing using a demo application that ships
>with Delphi 7, and the problem is there too.

>To me it seems, that you really can not use a single instance
>COM server from a Delphi program, without loosing memory!

>The simple example code below is enough to make the error
>occur. When the code is in a timer event, like below, the
>memory leak is easily seen in the task manager (the timer
>itself has nothing to do with the error).

>Has anyone seen this problem? Is there a solution to it?

>procedure TForm1.Timer1Timer(Sender: TObject);
>var
>  MyIntf: IPemacServerIntf;
>  a, b: Integer;
>begin
>  MyIntf := CoPemacServerIntf.Create;
>  MyIntf.Connect(a, b);
>end;

Other Threads