【问题标题】:Memory leak on simple HTTPRIO简单 HTTPRIO 上的内存泄漏
【发布时间】:2013-08-12 20:39:38
【问题描述】:

当我在我创建的 THTTPRIO 对象上退出应用程序时出现内存泄漏。

我的网络服务定义如下:

type
  TSimpleWebService = class
  protected
    FHTTPRIO : THTTPRIO;
  public
    constructor Create(URL : String);
    property HTTPRIO : THTTPRIO read FHTTPRIO;
  end;

implementation

constructor TSimpleWebService.Create(URL : String);
begin
  FHTTPRIO := THTTPRIO.Create(nil);
  FHTTPRIO.URL := URL;
end;

我正在测试/创建如下 Web 服务(CustomerCare 是我的 Web 服务接口):

procedure TfrmMain.Button1Click(Sender: TObject);
var
  webservice: customercare;
begin
  webservice := GetSimpleCustomerCareService;
  webservice := nil;
  frmMain.Close;
end;

function TfrmMain.getSimpleCustomerCareService: CustomerCare;
var
  webservice: TSimpleWebService;
begin
  webservice := TSimpleWebService.Create('http://this.is.a.test');
  Result := webservice.HTTPRIO as CustomerCare;
end;

当我单击 Button1 时,我实际上并没有做任何事情,只是创建了 web 服务,再次将其设置为 nil 并退出应用程序。那时(使用 ReportMemoryLeaksOnShutDown := True),我在 TSimpleWebService 上得到了 12 个字节的意外内存泄漏。

我尝试添加一个析构函数 Destroy,但它似乎没有被调用。

我错过了什么?

感谢您的意见, 一月

哦,是的,我使用的是 XE2 Windows 2003。除了 TSimpleWebservice 上的内存泄漏之外,我还在 TDictionary 对象上遇到了内存泄漏,但我不知道那个是从哪里来的。当我在 XE4/Windows 7 上编译和运行同一个项目时,我只得到 TSimpleWebservice 内存泄漏。

【问题讨论】:

    标签: delphi memory delphi-xe2 memory-leaks


    【解决方案1】:

    回答你的第二个问题:

    哦,是的,我使用的是 XE2 Windows 2003。除了 TSimpleWebservice 上的内存泄漏之外,我还在 TDictionary 对象上遇到了内存泄漏,但我不知道那个是从哪里来的。当我在 XE4/Windows 7 上编译和运行相同的项目时,我只得到 TSimpleWebservice 内存泄漏。

    wsdllookup.pas有内存泄漏,把这个文件复制到你的项目中找到这段代码

    destructor TWSDLLookup.Destroy;
    begin
      ClearWSDLLookup;
      inherited;
    end;
    

    改成:

    destructor TWSDLLookup.Destroy;
    begin
      ClearWSDLLookup;
      Flookup.Free;   // this was missing!!!!
      inherited;
    end;
    

    如您所见,此错误已在较新的 Delphi 版本中得到修复

    【讨论】:

      猜你喜欢
      • 2012-04-03
      • 1970-01-01
      • 1970-01-01
      • 2012-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多