问题描述
我正在使用Delphi 1 16位学习Pascal(不要笑,它工作正常,加上我买不起更新版本)。我使用TList来容纳一个简单的通讯录的对象引用。每个对象都被添加到TList中: DataList.Add(TAddrBookData.Create('Bob','1 Mill St '));
我需要自己释放TAddrBookData对象吗?或者当TList.Free运行时,它们是否释放?
您需要自己释放它们。后来的版本带有一个TObjectList,它就像一个TList,除了它只接受对象,它可以选择拥有所有权,并在释放列表时自动释放它们。但是我不相信Delphi 1中存在TObjectList,所以你必须手动处理。
I'm using Delphi 1 16-bit to learn Pascal (don't laugh, it works fine, plus I can't afford a more recent version). I'm using a TList to hold object references for a simple address book. Each object is added to the TList like so:
DataList.Add(TAddrBookData.Create('Bob', '1 Mill St'));
Do I need to free the TAddrBookData objects myself? Or are they freed when TList.Free is run?
You need to free them yourself. Later versions come with a TObjectList, which is like a TList except it will only accept objects and it has the option to take ownership and free them for you automatically when the list is freed. But I don't believe TObjectList existed in Delphi 1, so you'll have to take care of it manually.
这篇关于我需要释放这些物品吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!