我有以下代码创建RemObjects服务的实例并调用.net服务器
class function TLabelPrintingServiceProxy.GetInstance: ILabelPrintingManager;
var
LRoRemoteService: TRoRemoteService;
begin
LRoRemoteService := TRoRemoteService.Create(nil);
LRoRemoteService.Message := TROSOAPMessage.Create();
LRoRemoteService.Channel := TROIndyHTTPChannel.Create(nil);
LRoRemoteService.Channel.TargetUri := TROUri.Create(ILabelPrintingIntf.LabelPrintingManager_EndPointURI);
Result := (LRoRemoteService as ILabelPrintingManager);
end;
调用.net服务的方式如下:
try
Result := BinaryArray.Create;
LLabelPrintingManager := TLabelPrintingServiceProxy.GetInstance();
Result.Add(LLabelPrintingManager.GetVSSLabelImage(APrintJob));
finally
TLabelPrintingServiceProxy.ReleaseLabelPrintingServiceProxyInstance(LLabelPrintingManager);
end;
调用完成后,RemObjects应自动释放LLabelPrintingManager接口,但它不会泄漏使用的对象。
我已尝试使用ReleaseLabelPrintingServiceProxyInstance(代码如下)手动释放服务实例中的所有对象,但它仍然在泄漏
class procedure TLabelPrintingServiceProxy.ReleaseLabelPrintingServiceProxyInstance(aILabelPrintingManagerIntf: ILabelPrintingManager);
var
lProxy: TRoProxy;
begin
lProxy := TROProxy(aILabelPrintingManagerIntf);
TROIndyHTTPChannel(lProxy.__TransportChannel).TargetUri.Free;
// TROIndyHTTPChannel(lProxy.__TransportChannel).Free; this is generating an AV
TRoMessage(lProxy.__Message).free;
TRoRemoteService(aILabelPrintingManagerIntf).Free;
我错过了什么?
答案 0 :(得分:0)
与RemObjects的人讨论后,这是解决方案:
class function TLabelPrintingServiceProxy.GetRemoteServiceInstance: TRoRemoteService;
var
LRoRemoteService: TRoRemoteService;
begin
Result := TRoRemoteService.Create(nil);
Result.Message := TROSOAPMessage.Create();
Result.Channel := TROIndyHTTPChannel.Create(nil);
Result.Channel.TargetUri := TROUri.Create(ILabelPrintingIntf.LabelPrintingManager_EndPointURI);
end;
呼叫
try
LLabelPrintingRemoteService := TLabelPrintingServiceProxy.GetRemoteServiceInstance();
(LLabelPrintingRemoteService as ILabelPrintingManager).PrintVSSJob(printJob);
finally
TLabelPrintingServiceProxy.ReleaseLabelPrintingServiceProxyInstance(LLabelPrintingRemoteService);
end;
并释放对象
try
LLabelPrintingRemoteService := TLabelPrintingServiceProxy.GetRemoteServiceInstance();
(LLabelPrintingRemoteService as ILabelPrintingManager).PrintVSSJob(printJob);
finally
TLabelPrintingServiceProxy.ReleaseLabelPrintingServiceProxyInstance(LLabelPrintingRemoteService);
end;