加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi字符串泄漏

发布时间:2020-12-15 10:04:50 所属栏目:大数据 来源:网络整理
导读:我正在使用Delphi XE,并编写一个使用RemObjects SDK进行通信的应用程序(如果可能相关).我有FastMM调试,有时(并不总是)当我关闭它时会发出一个警告,说明单个“意外的内存泄漏”. “发生意外的内存泄漏.意外的小块泄漏是:117-124字节:UnicodeString x 1”.偶
我正在使用Delphi XE,并编写一个使用RemObjects SDK进行通信的应用程序(如果可能相关).我有FastMM调试,有时(并不总是)当我关闭它时会发出一个警告,说明单个“意外的内存泄漏”. “发生意外的内存泄漏.意外的小块泄漏是:117-124字节:UnicodeString x 1”.偶尔,我得到x2报告.

现在,我的理解是字符串是引用计数,并且由于没有其他对象导致泄漏,可能导致这种情况发生的情况是什么?在this StackOverflow question人们找不到泄漏的方法.

如果没有明显的方法,那么我将下载最新的FastMM源(它似乎不包含在XE源中).

[编辑一旦解决]找到这个的解决方案是安装FastMM源,并启用FullDebugMode来获取堆栈跟踪.

解决方法

想到的唯一方法就是使用threadvar,在不故意破坏字符串的情况下泄漏字符串(例如手动递增引用计数或执行一些混乱的指针操作).

像帮助文件所述,

Dynamic variables that are ordinarily
managed by the compiler (long strings,
wide strings,dynamic arrays,
variants,and interfaces) can be
declared with threadvar,but the
compiler does not automatically free
the heap-allocated memory created by
each thread of execution. If you use
these data types in thread variables,
it is your responsibility to dispose
of their memory from within the
thread,before the thread terminates.

除此之外,没有任何想到的事情尚未阐明.

[提问者编辑]这确实是问题,具体代码如下:

threadvar
    g_szAuthentication : String;


procedure TMyBase.SetAuthentication(szUserName,szPassword: String);
begin
    g_szAuthentication := '?name=' + szUserName + '&pass=' + szPassword;
end;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读