Delphi 开启内存泄漏报告模式


本文整理自网络,侵删。

 

 

function TfrmMainForm.GetSelectedConnection: TIdTCPConnection;

var

    PairEnum: TObjectDictionary.TPairEnumerator;

    Conn: TIdTCPConnection;

    IPS:STRING;

begin

    //从列表中选择,返回    TIdTCPConnection;为后续的关闭做准备

 

  ReportMemoryLeaksOnShutdown := True;//开启内存泄漏报告模式

    try

       if  ServerContainer1.FTCPConnection  =nil   then

       begin

         showmessage('ServerContainer1.FTCPConnectio =nil');

       end;

      PairEnum := ServerContainer1.FTCPConnection.GetEnumerator;

      while PairEnum.MoveNext do

       begin

          ips := PairEnum.Current.Key;

          if  L_UserLink.Selected=nil then

              exit;

          if L_UserLink.Selected.SubItems[0]=ips then

            result:=PairEnum.Current.Value;

       end;

    finally

      PairEnum.CleanupInstance; 

 

{一般人没有加上面这行代码所以会报错 An unexpected memory leak has occured. the unexpected smal block                       leaks are

 

解决办法是在FREE之前加  CleanupInstance; 

 

} 

      PairEnum.Free;

    end;

 

end;

 

来源:https://blog.csdn.net/qq_25439957/article/details/88635643

 

相关阅读 >>

Delphi 返回整数的四种情况

Delphi 无边框窗体常见问题

md5unit.pas

Delphi 读url下txt中的下载地址的简单下载者代码

Delphi中如何实现模糊查找文件

Delphi根据输入日期按年月周日输出日期段

Delphi的字符串与16进制的相互转换函数的汇编代码

Delphi 判断操作系统是否是64位的函数

Delphi 调用批处理

Delphi中format函数的用法

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...