Rob Smythe
Rob Smythe

Reputation: 429

releasing arrays

I'm using three arrays of strings--ten questions, ten answers, and ten hints, read from a text file. A button comes up asking the user to choose another category, refills the arrays, and starts over with new questions and answers and hints.

Do I declare the arrays and init them in ViewDidLoad, remove objects and add new ones during the game, and release them in dealloc? Or do I alloc and release them each time through the loop?

Upvotes: 0

Views: 64

Answers (2)

勿绮语
勿绮语

Reputation: 9320

Each individual element needs to be alloc'ed before being added to the array, and released once it's added. When you release, you only need to release the array itself, but not individual element - that's again taken care of for you.

Upvotes: 1

allaire
allaire

Reputation: 6045

If I understood correctly, I would do option #1. just clear your array, and use the same one with your new strings. No reason to dealloc/realloc the array each time if you only need to change the values of it.

Upvotes: 0

Related Questions