Calling methods from other services

Hi,

I’am trying to call methods from other services as suggested in “Calling a service method from inside the server with Code-First? - #4 by EvgenyK
It works, except if I raise an error, there is a huge memory leak, as the service is not freed.
Can you help me with this ?

function TFirstService.GetServerTime: DateTime;
var
  instance: IInterface;
  service: TSecondService;
  objactivation:IROObjectActivation;
begin
  service := TSecondService.Create(nil);
  instance := service;

  try

    if Supports(instance, IROObjectActivation, objactivation) then begin
      objactivation.OnActivate(ClientID, nil);
      objactivation := nil;
    end;

    Result := service.GetServerTime();

    // Raising an exception here causes a memoryleak. service is not freed
    raise EROHttpApiException.Create(501, 'No acccess');     //  MEMORY LEAK ?????

    if Supports(instance, IROObjectActivation, objactivation) then begin
     objactivation.OnDeactivate(ClientId);
     objactivation := nil;
    end;
  finally
    instance := nil;
  end;
end;

Hi,

I cannot reproduce any memory leak. service are cleared at instance := nil; line.
also FastMM doesn’t report about any leaks.

Can you create a simple testcase that reproduces your case and FastMM reports about memory leaks, pls?

Hi,

Attached a small test-project

You can call it from a browser with

http://localhost:8099/api/ApiService/GetOrder

or from the Delphi REST debugger:

The value of parameters “Parameters” and “LamKey” is not imported here. Any value will do.

It seems that the NewDataset instruction causes this memory-leak, but only when an exception is raised.

function TDataService.GetOrder(const aGebruikerId, aParameters: string): string;

begin

result := ‘’;

var DS := Connection.NewDataset(’’) as IDAServerDataset;

// …

end;

Met vriendelijke groeten, Salutations distinguées,

Mit freundlichen Grüßen, Kind regards, Z poważaniem,

Freddy Tutak

image002.jpg

TpiCom bv

Mobile : +32 498 10 52 69

www.tpicom.eu

TestCase1.zip (1.55 MB)

Hi,

try to put deactivation into finally section:

 ...
  finally
    if Supports(instance, IROObjectActivation, objactivation) then begin
     objactivation.OnDeactivate(ClientId);
     objactivation := nil;
    end;
    instance := nil;
  end;

it should solve this issue

Hi Evgeny,

Thanks a lot.
It’s OK now …

Met vriendelijke groeten, Salutations distinguées,

Mit freundlichen Grüßen, Kind regards, Z poważaniem,

Freddy Tutak

image002.jpg

TpiCom bv

Mobile : +32 498 10 52 69

www.tpicom.eu

~WRD000.jpg