Memory Leak and unexpected json

Hi,

I make a service function like this in xdataserver to call another xdataserver, but when my client makes a call there will be an error "java.net.ProtocolException: Unexpected status line: {."
function TApiGuest.ListGuest: TList<TTGuest>;
var
  MidClient: TXDataClient;
begin
  MidClient := CreateLocalClient;
  TXDataOperationContext.Current.Handler.ManagedObjects.Add(MidClient);

  Result := MidClient.List<TTGuest>('ORDER BY FID');
  if Result = nil then
    raise EXDataHttpException.Create(400, 'Data not found');


  TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result);
end;

but when I delete the line to destroy MidClient it becomes like this.
function TApiGuest.ListGuest: TList<TTGuest>;
var
  MidClient: TXDataClient;
begin
  MidClient := CreateLocalClient;

  Result := MidClient.List<TTGuest>('ORDER BY FID');
  if Result = nil then
    raise EXDataHttpException.Create(400, 'Data not found');

  TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result);
end;

The client can call the function without any errors. but there will be a memory leak on the server. how should i fix the following code?

thank you

this happens on the Android xdataclient application, whereas if on Windows there are no problems.

Hello Megat, try this. I also find it strange you use "ORDER BY FID". That's not valid XData syntax. Shouldn't it be "$orderby=FID".


function TApiGuest.ListGuest: TList<TTGuest>;var  MidClient: TXDataClient;begin  MidClient := CreateLocalClient;  TXDataOperationContext.Current.Handler.ManagedObjects.Add(MidClient);  MidClient.ReturnedInstancesOwnership := TInstanceOwnership.None;
  Result := MidClient.List<TTGuest>('$orderby=FID');  if Result = nil then    raise EXDataHttpException.Create(400, 'Data not found');end;



Hi Wagner, thanks for the correction. but with the orderby error that I used no error message was displayed.
by setting the ReturnedInstancesOwnership property, now my code is running well.