I have tasks which are sending various messages with data.
For example:
task.Comm.Send(MSG_JOB_ERROR,[string, string,string,string,string, TObject]) ;
On the receiving side I have
procedure TUDPBroadCast.OnWorkerJobError(var msg: TOmniMessage);
var
s : String ;
begin
try
s := 'TASK: ' + msg.MsgData.AsArrayItem[0].AsString + ', IP: ' +
msg.MsgData.AsArrayItem[1].AsString + ', PORT: ' +
msg.MsgData.AsArrayItem[2].AsString +
', DATA: ' + msg.MsgData.AsArrayItem[3].AsString + ', REPLY: '+
msg.MsgData.AsArrayItem[4].AsString ;
Xlog('JOB ERROR > ' + s, 'UDPBroadCast') ;
processworkobject(msg.MsgData.AsArrayItem[4].AsObject) ;
finally
msg.MsgData.Clear ;
end;
end;
But I don't feel that MsgData.Clear will correctly unallocate all memory.
What is the correct handling of TomniValue deallocation?
msg.MsgData is a TOmniValue. In the most recent versions of OmniThreadLibrary, TOmniValue can own its object by setting TOmniValue.OwnsObject:=True, and has some other helper methods to facilitate this functionality. If OwnsObject is true, then the object is freed when the TOmniValue is freed, so you do not have to worry about memory management as much any longer.