Async in Delphi (Remoting SDK 10.x)

Please confirm if I have a misunderstanding of the Delphi Async interface
I was under the impression I could call ‘invoke’, wait until answer received then set the Async service to nil and everything would be done. Under memory leak testing I notice procedure TROBaseSuperChannelWorker.DoExecute;
lData: TROBinaryMemoryStream; // This is not freed in this instance, or at least not for a long time which doesn’t work in high speed processing

Whilst you are considering the below, what is the best way to ‘wait for answer received to be true’ in a non-ui multi-threaded application.

Basic example:

procedure( .... )
var
service: ILogServerService_Async;
begin

  service := CoLogServerService_Async.create( ... );
  try
   service.Invoke_log_Message(....);                                 
   while not service.AnswerReceived do
   sleep(10);
   //NEVER do this.... service.Retrieve_Log_Message;

  except
  end;
//Service is interface, would free here automatically
end);

Hi,

You are right.
we have the Async example that demonstrate usage of _Async interface.

Do you mean this code:

lData := TROBinaryMemoryStream.Create;
try
..
  Self.IncomingData(lTmpId, lData);
except
  FreeOrDisposeOf(lData); // only free when we failed to send the data to the queue

?
lData object is freed in TROInvokerQueueItem.Destroy; (server-side) or in TROBaseSuperChannel.HasData/TROBSCPooledEvent.Destroy; (clent-side)

I can suggest to use _AsyncEx interface. here you specify callback method that is called when server’s response is received.
the Phone Photo Server sample demonstrates usage of _AsyncEx interface.

Let me add some further explanation…

  1. I am finding a memory leak or seriously delayed cleanup when we don’t use service.Retrieve_…();
    From what I can see a TROWaitRequest is created - maybe it free’s after a long period of time but not with the procedure ending
  2. I’ll need to see how i could use callbacks that allow the calling thread to pause until the callback is returned… Is there an example on this somewhere?

you can use TEvent with SetEvent/ResetEvent/WaitFor methods
see more at Waiting for a Task to Be Completed