Logicsaurus Rex
Logicsaurus Rex

Reputation: 3192

Reuse or renew an NSMutableArray

If you have an array you're going to completely repopulate many times during an applications lifetime, would it be better memory-consumption/allocation-wise to...

  1. alloc-init a new instance when I'm ready to repopulate, or
  2. removeAllObjects on the existing instance to repopulate

Upvotes: 0

Views: 41

Answers (1)

rmaddy
rmaddy

Reputation: 318804

As is typical with such a broad question, the answer is "it depends".

The better answer is, "don't worry about it". Seriously, this is called premature optimization. Unless you run into a real memory issue, either approach will result in negligible differences.

Upvotes: 2

Related Questions