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

delphi – TStringList是否可以自动释放附加到其项目的对象?

发布时间:2020-12-15 04:00:53 所属栏目:大数据 来源:网络整理
导读:我将一些TObject后代添加到TStringList,例如通过调用AddObject.当我释放列表对象时,我希望它们被释放.有没有办法实现这个目标? 解决方法 TStringList的 OwnsObjects 属性应设置为True,以便列表在销毁时释放其对象.这可以通过调用 constructor overload that
我将一些TObject后代添加到TStringList,例如通过调用AddObject.当我释放列表对象时,我希望它们被释放.有没有办法实现这个目标?

解决方法

TStringList的 OwnsObjects属性应设置为True,以便列表在销毁时释放其对象.这可以通过调用 constructor overload that receives the OwnsObjects parameter或通过在创建后显式设置属性来实现.最好将OwnsObjects设置为对象构造的一部分.

documentation描述了这样的属性:

The OwnsObjects property specifies whether the string list owns the stored objects or not. If the OwnsObjects property is set to True,then the Destroy destructor will free up the memory allocated for those objects.

(编辑:李大同)

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

    推荐文章
      热点阅读