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

我将一些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.

相关文章

 从网上看到《Delphi API HOOK完全说明》这篇文章,基本上都...
  从网上看到《Delphi API HOOK完全说明》这篇文章,基本上...
ffmpeg 是一套强大的开源的多媒体库 一般都是用 c/c+&#x...
32位CPU所含有的寄存器有:4个数据寄存器(EAX、EBX、ECX和ED...
1 mov dst, src dst是目的操作数,src是源操作数,指令实现的...