Clear a TList or a TObjectList

后端 未结 5 1424
故里飘歌
故里飘歌 2021-02-19 05:33

I\'m a bit puzzled of what to use for storing objects in a list. Until now I have used TList and freed each item in a loop. Then I discovered TObjectList

5条回答
  •  半阙折子戏
    2021-02-19 06:26

    It's not the same TList.Clear only frees the memory allocated to store the pointers, not objects they are pointing to. To avoid memory leaks you need to free the memory yourself - as you have been doing - or use TObjectList.

    To answer the second question, TObjectList doesn't support storing records. You need to use TList (or something else) in that case.

提交回复
热议问题