Delphi-无法释放结构的字符串[FastMM管理器] [英] Delphi - structures' strings not being freed [FastMM manager]

查看:99
本文介绍了Delphi-无法释放结构的字符串[FastMM管理器]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我声明

PSomeStruct = ^TSomeStruct;
TSomeStruct = record 
  s1 : string;
end;

然后运行以下代码:

var
  p: PSomeStruct;
begin
  new(p);
  p^.s1:= 'something bla bla bla';
  dispose(p);

FastMM 4内存管理器报告存在内存泄漏(类型:字符串,数据转储:东西bla bla bla").但是,如果在调用dispose之前确实将s1字符串设置为空,就可以了.

the FastMM 4 memory manager reports that there was a memory leak (type: string, data dump: "something bla bla bla"). However, if I do set the s1 string to empty before calling dispose it's OK.

我发现的第二种方法是从记录类型更改为类,然后创建实例,而不是创建new实例,并调用instance.Free()而不是dispose实例.它无需手动清洁琴弦即可工作.

The second way I found is to change from record type to class, then instead of new I'm creating the instance, and instead of dispose I'm calling instance.Free(). It works without manually cleaning the strings.

当我调用dispose时,是否可以使Delphi自动清理字符串?

Is there a way to make Delphi automatically clean my strings when I call dispose?

推荐答案

FastMM是您的.dpr中使用的第一个单位吗?否则,可能太早完成,报告错误的内存泄漏.

Is FastMM the first unit used in your .dpr? Otherwise it could be finalized too early, reporting false memoryleaks.

这个简化的代码样本还会产生与使用JvSimpleXML时相同的内存泄漏吗?如果不是这种情况,那么您可能会怀疑还有更多的事情发生.

And does this simplified codesample also generate the same memoryleak as when you use your JvSimpleXML? When it's not, there is probably more going on then you suspect.

我认为:当FastMM报告内存泄漏时,就会出现内存泄漏.

In my opinion: when FastMM reports a memory leak, there is a memoryleak.

这篇关于Delphi-无法释放结构的字符串[FastMM管理器]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆