Apache + Delphi XE7 + Datasnap. Problems with memory

4

Developed a program with Apache, Delphi XE7 and Datasnap. My Apache httpd.exe consumes memory until I give the message "Out of Memory" so I need to restart Apache.

I configured ServerModule (FireDac components, Mysql) and WebModule to run a simple query.

In the Client I have a DBGrid that shows the Query results

With the Task Manager open and monitoring the memory:

  • When you connect and disconnect the TSQLConnection or open and close the TClientDataSet the memory increases.

What I've tried to do:

I ran Pascal Analyzer looking for memory leaks but it's ok, I tried shutting down the keep alive Apache but it did not make any difference, I already used all types of WebModule lifecycle (Session, Server and Invocation) but the problem persists.

Thanks in advance.

    
asked by anonymous 24.04.2015 / 14:56

2 answers

1

Try the code below, I believe it helps.

procedure TformPrincipal.LimpaMemoria;
var
   MainHandle : THandle;    
begin
   try
      MainHandle := OpenProcess(PROCESS_ALL_ACCESS, false, GetCurrentProcessID) ;
      SetProcessWorkingSetSize(MainHandle, $FFFFFFFF, $FFFFFFFF) ;
      CloseHandle(MainHandle) ;

   except
   end;

   Application.ProcessMessages;
end;
    
06.06.2015 / 13:29
0

The above solution is very good, but to be used on the client. On the server, if larger searches are done, it will be difficult to have memory for everyone.

On the server, give preference to using as few as possible. Turn off the FireDac options that create cache information and change the pointer from FireDac to unidirecional . Let the client cache the data (or transmit them via json or whatever).

Also be sure to use the Release method instead of the free method. Release removes the memory used by the cursor (and other memory eaters), while free ignores all of that.

    
22.12.2017 / 04:16