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 goto 语句的使用

Delphi webbrowser.oleobject属性

Delphi winsock远程唤醒计算机的函数

Delphi中如何判断是否有程序全屏

Delphi制作透明窗体

Delphi xe2 - 实现主窗口在任务栏上不显示

Delphi 自动关闭弹出的窗口

Delphi indy smtp 发送邮件

Delphi剪切板-监视剪贴板

Delphi 倒计时对话框

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



打赏

取消

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

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

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

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

评论

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