Board index » delphi » Memory usage from Remote Data Modules

Memory usage from Remote Data Modules


2008-07-01 08:18:12 PM
delphi129
Hi all.
I'm using a Remote Data Module in a Apache Server, and clients using
TWebConnection.
My RDM is a .exe. Everthing is ok, but I have a little problem:
My app clients are connecting with the RDM in 1 minute intervals to perform
some operations.
In each connection, the RDM consumes a amount X of memory, and does not free
that memory after disconnecting.
The executable process stays running all the time and the memory usage is
always increasing.
I wrote an FreeAndNil(self) (self=RDM) but does not matter.
What is wrong?
Sorry for my bad english, and thanks in advance.
Ricardo Carmo
 
 

Re:Memory usage from Remote Data Modules

Missing information:
Delphi 7, Win2K server
Ricardo Carmo
"Ricardo Carmo" <XXXX@XXXXX.COM>escreveu na mensagem
Quote
Hi all.

I'm using a Remote Data Module in a Apache Server, and clients using
TWebConnection.
My RDM is a .exe. Everthing is ok, but I have a little problem:

My app clients are connecting with the RDM in 1 minute intervals to
perform
some operations.
In each connection, the RDM consumes a amount X of memory, and does not
free
that memory after disconnecting.

The executable process stays running all the time and the memory usage is
always increasing.
I wrote an FreeAndNil(self) (self=RDM) but does not matter.

What is wrong?

Sorry for my bad english, and thanks in advance.

Ricardo Carmo


 

Re:Memory usage from Remote Data Modules

Hi Ricardo;
There can be lots of circunstances ...
Are you creating RDM in your own code?. How?. In the main thread?.
What kind of components are you creating for each RDM instance?. Are you
cleanning those components after using them?.
Phil.
 

Re:Memory usage from Remote Data Modules

Hello Phil.
Quote
Are you creating RDM in your own code?. How?. In the main thread?.
No. I am using a "blank" RDM, created by Wizard in
File->New->Other->Multitier->Remote Data Module.
Quote
What kind of components are you creating for each RDM instance?. Are you
cleanning those components after using them?.
I'm using the components that I need: IBDatabase, IBQuerys,
DataSetProviders.
Some components are created in design time, others in runtime.
And yes, I am cleanning those components. What I did was:
a) My RDM have a method "CloseMyConnection" executed by the client app.
This method perform a RDM.Components[0].Free while ComponentCount>0;
After all, this method perform a FreeAndNil(self) where self is the RDM.
b) The client app perform a RDM.Disconnect.
In this time, all works fine, but the executable process stays running, and
the
allocated memory does not decrease.
Any ideas?
Thanks.
"PhilDGS" <XXXX@XXXXX.COM>escreveu na mensagem
Quote
Hi Ricardo;

There can be lots of circunstances ...
Are you creating RDM in your own code?. How?. In the main thread?.
What kind of components are you creating for each RDM instance?. Are you
cleanning those components after using them?.

Phil.


 

Re:Memory usage from Remote Data Modules

Hi Ricardo;
Try to destroy RDM from outside of it (same level in where you created it),
and see what happen.
Phil
 

Re:Memory usage from Remote Data Modules

HI Phil, thanks for your help...
Quote
Try to destroy RDM from outside of it (same level in where you created
it),
How? I don't know to do this. Because...
the httpsrvr.dll launches the RDM executable ( I am using WebConnection on
the client);
I think that the RDM is created on the code below:
initialization
TComponentFactory.Create(ComServer, TMyRDM,
Class_MyRDM, ciMultiInstance, tmApartment);
But this source-code is on the RDM's unit...
I'm confused. Can you help me?
Ricardo.
"PhilDGS" <XXXX@XXXXX.COM>escreveu na mensagem
Quote
Hi Ricardo;

Try to destroy RDM from outside of it (same level in where you created
it),
and see what happen.

Phil


 

Re:Memory usage from Remote Data Modules

Hi Ricardo;
That's sound much better !!!, because it is suposed RDM will be automatically
destroyed when you close the client connection. So, try to left it alone (I
mean, don't call your RDM.CloseMyConnection).
At least, I use DataSnap/Midas and RDMs are created/destroyed automatically
when each client connects/disconnects.
Phil
 

Re:Memory usage from Remote Data Modules

Quote
How? I don't know to do this. Because...
the httpsrvr.dll launches the RDM executable ( I am using WebConnection on
the client);
PhilDGS is right. Do NOT free your RDM manually, calling a remote method
from the client application.
Whenever you close the WebConnection (freeing it or closing it explicitly)
your RDM instance will be destroyed as well.
Try to put some OutputDebugString in OnDestroy event handler, like this:
procedure TMyRemoteDM.RemoteDataModuleDestroy(Sender: TObject);
begin
OutputDebugString(PChar(ClassName + '.Destroy'));
end;
You can play with it and see if it is being destroyed as you close the
connections.
PS: Use DebugView (download.sysinternals.com/Files/DebugView.zip) to
"catch" the OutputDebugString messages.
Regards.
 

Re:Memory usage from Remote Data Modules

Alexandre and Phil,
I have discovered that the problem is in the client app.
My client app is a Windows Service. If I do connect to RDM from a Windows
App,
the RDM is destroyed after close connection, but if I connect from a Windows
Service,
the RDM is not destroyed. Any ideas?
Thanks.
Ricardo Carmo
"Alexandre Machado" <alexandre@f#ckspamconsultbrasil.com.br>escreveu na
mensagem news:XXXX@XXXXX.COM...
Quote
>How? I don't know to do this. Because...
>the httpsrvr.dll launches the RDM executable ( I am using WebConnection
on
>the client);

PhilDGS is right. Do NOT free your RDM manually, calling a remote method
from the client application.
Whenever you close the WebConnection (freeing it or closing it explicitly)
your RDM instance will be destroyed as well.

Try to put some OutputDebugString in OnDestroy event handler, like this:

procedure TMyRemoteDM.RemoteDataModuleDestroy(Sender: TObject);
begin
OutputDebugString(PChar(ClassName + '.Destroy'));
end;

You can play with it and see if it is being destroyed as you close the
connections.

PS: Use DebugView (download.sysinternals.com/Files/DebugView.zip)
to
"catch" the OutputDebugString messages.

Regards.


 

Re:Memory usage from Remote Data Modules

Dear friends,
I have discovered that:
1. If I disconnect from the RDM with no RDM methods called, the RDM is
destroyed.
2. If I call any method from the RDM, after disconnect the RDM does not
destroyed.
What's wrong?
Ricardo
"Alexandre Machado" <alexandre@f#ckspamconsultbrasil.com.br>escreveu na
mensagem news:XXXX@XXXXX.COM...
Quote
>How? I don't know to do this. Because...
>the httpsrvr.dll launches the RDM executable ( I am using WebConnection
on
>the client);

PhilDGS is right. Do NOT free your RDM manually, calling a remote method
from the client application.
Whenever you close the WebConnection (freeing it or closing it explicitly)
your RDM instance will be destroyed as well.

Try to put some OutputDebugString in OnDestroy event handler, like this:

procedure TMyRemoteDM.RemoteDataModuleDestroy(Sender: TObject);
begin
OutputDebugString(PChar(ClassName + '.Destroy'));
end;

You can play with it and see if it is being destroyed as you close the
connections.

PS: Use DebugView (download.sysinternals.com/Files/DebugView.zip)
to
"catch" the OutputDebugString messages.

Regards.


 

Re:Memory usage from Remote Data Modules

Ricardo;
Opt. 1 is the right way. Simply disconnect the client and the server will
destroy the RDM alone.
Phil.
 

Re:Memory usage from Remote Data Modules

Sorry, my english is poor. You don't understand what I sayd.
If app client connects to RDM and does not call a RDM's function or
procedure,
when it disconnects, the DRM is destroyed. that is ok.
But...
If app client connects to RDM and CALLS a RDM's function or procedure after
that,
when it disconnects, the RDM is not destroyed.
Do you undestand now?
"PhilDGS" <XXXX@XXXXX.COM>escreveu na mensagem
Quote
Ricardo;

Opt. 1 is the right way. Simply disconnect the client and the server will
destroy the RDM alone.

Phil.


 

Re:Memory usage from Remote Data Modules

I just found the fix to the bug:
www.distribucon.com/midasbug/results.asp
This bug applies only to TWebConnection.
Thanks Phil.
Problem fixed.
Ricardo.
"Ricardo Carmo" <XXXX@XXXXX.COM>escreveu na mensagem
Quote
Sorry, my english is poor. You don't understand what I sayd.

If app client connects to RDM and does not call a RDM's function or
procedure,
when it disconnects, the DRM is destroyed. that is ok.

But...

If app client connects to RDM and CALLS a RDM's function or procedure
after
that,
when it disconnects, the RDM is not destroyed.

Do you undestand now?


"PhilDGS" <XXXX@XXXXX.COM>escreveu na mensagem
news:XXXX@XXXXX.COM...
>Ricardo;
>
>Opt. 1 is the right way. Simply disconnect the client and the server
will
>destroy the RDM alone.
>
>Phil.
>
>


 

Re:Memory usage from Remote Data Modules

Ok Alexandre, sua idéia de debugar o evento onDestroy serviu pra
constatar que o RDM não estava sendo destruído quando o cliente se
desconectava.
Eu encontrei na internet a explicação e a solução para este problema.
Tratava-se de um bug do Delphi 7 cuja solução foi apresentada no
link abaixo:
www.distribucon.com/midasbug/results.asp
Que bom que eu encontrei. Se não desse pra resolver, esta solução de
utilizar RDM via HTTP ficaria inviável.
De qualquer modo, obrigado.
Ricardo Carmo
"Alexandre Machado" <alexandre@f#ckspamconsultbrasil.com.br>escreveu na
mensagem news:XXXX@XXXXX.COM...
Quote
>How? I don't know to do this. Because...
>the httpsrvr.dll launches the RDM executable ( I am using WebConnection
on
>the client);

PhilDGS is right. Do NOT free your RDM manually, calling a remote method
from the client application.
Whenever you close the WebConnection (freeing it or closing it explicitly)
your RDM instance will be destroyed as well.

Try to put some OutputDebugString in OnDestroy event handler, like this:

procedure TMyRemoteDM.RemoteDataModuleDestroy(Sender: TObject);
begin
OutputDebugString(PChar(ClassName + '.Destroy'));
end;

You can play with it and see if it is being destroyed as you close the
connections.

PS: Use DebugView (download.sysinternals.com/Files/DebugView.zip)
to
"catch" the OutputDebugString messages.

Regards.