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( .... )
service: ILogServerService_Async;

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

//Service is interface, would free here automatically


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

Do you mean this code:

lData := TROBinaryMemoryStream.Create;
  Self.IncomingData(lTmpId, lData);
  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