FrankCM
FrankCM

Reputation: 207

Do I need to free these objects?

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?

Upvotes: 12

Views: 754

Answers (2)

Mason Wheeler
Mason Wheeler

Reputation: 84550

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.

Upvotes: 12

AlexV
AlexV

Reputation: 23098

You will need to free (or FreeAndNil) those as well.

If you want to learn Object Pascal (Delphi) with a newer (and free) IDE try Lazarus as the free Turbo Delphi 2006 has been discontinued (what a bad move).

Upvotes: 8

Related Questions