Datasnap server not freeing memory

  

I have a datasnap server that runs as a service on a Windows PC, the service connects to a database on the same Windows PC – it reads and writes to and from the database via the server method calls from a client app which runs on iOS and Android devices.

One thing I have noticed when monitoring the service is that the memory consumption appears to increase every time a server method is called, like its not being freed/released.

Can anyone advise anything to check regarding this? Am I missing something?

Below is sample code from the client and server, this is just one of many methods that are called.

Client:

Data Module –

function TDataMod.StartOperation(EmployeeID: integer): integer;
var ServerMethods1Client : TServerMethods1Client;
begin
ServerMethods1Client := nil;

if not SQLConnection1.Connected
then SQLConnection1.Open;

if SQLConnection1.Connected then
begin
ServerMethods1Client := TServerMethods1Client.Create(SQLConnection1.DBXConnection, True);
try
Result := ServerMethods1Client.StartOperation(EmployeeID);
finally
SQLConnection1.Close;
ServerMethods1Client.Free;
ServerMethods1Client := nil;
end;
end;
end;

Methods Unit –

function TServerMethods1Client.StartOperation(aEmployeeID: Integer;): Integer;
begin
if FStartOperationCommand = nil then
begin
FStartOperationCommand := FDBXConnection.CreateCommand;
FStartOperationCommand.CommandType := TDBXCommandTypes.DSServerMethod;
FStartOperationCommand.Text := ‘TServerMethods1.StartOperation’;
FStartOperationCommand.Prepare;
end;

FStartOperationCommand.Parameters[0].Value.SetInt32(aEmployeeID);
FStartOperationCommand.ExecuteUpdate;
Result := FStartOperationCommand.Parameters[1].Value.GetInt32;
end;

Server:

ServerMethodsUnit –

function TServerMethods1.StartOperation(aEmployeeID: integer): integer;
begin
try
Result := dmData.StartOperation(aEmployeeID);
finally
GetInvocationMetadata.CloseSession := True;
end;
end;

Data Module –

function TData.StartOperation(EmpID: integer): integer;
begin
Result := -1;

with tfdQuery1 do
begin
Close;
SQL.Text := ‘select db._StartOperationEvent(:EmployeeID)’;
ParamByName(‘EmployeeID’).AsInteger := EmpID;
try
Open;
Result := (fields[0].AsInteger);
except
on e : Exception do
WriteToLog(E.Message);
end;
Close;
UnPrepare;
end;
end;

constructor Create(ADBXConnection: TDBXConnection; AInstanceOwner: Boolean); overload;
destructor Destroy; override;

constructor TServerMethods1Client.Create(ADBXConnection: TDBXConnection; AInstanceOwner: Boolean);
begin
inherited Create(ADBXConnection, AInstanceOwner);
end;

destructor TServerMethods1Client.Destroy;
begin
FStartOperation.DisposeOf;
inherited;
end;

The lifecycle property of the TDSServerClass component is set to Session.

If any other information is required then please let me know, thanks.

Comments are closed.