0

I have a static array in my class. When do i release it? or I don't have to worry about it? I was thinking about releasing it in dealloc method but not sure. Thanks

BukLau
  • 69
  • 3

2 Answers2

2

If it's static, you shouldn't release it.

MRAB
  • 20,356
  • 6
  • 40
  • 33
  • Thanks, but can you tell me why? – BukLau Jun 02 '11 at 03:07
  • The rule is basically that if you created it and no longer want it, you release it, so that if nothing else has retained it, it will be deallocated. The static array belongs to the class and it's the responsibility of the class to release it. If you release it, it will may be deallocated, but the class may still try to use it (the class will try to release it at some point), but it no longer exists. – MRAB Jun 02 '11 at 16:04
1

If you are concerned about the amount of memory the array takes up (because it's potentially large and is something that you can always recreate if needed), you can empty the array upon receiving a didReceiveMemoryWarning notification. Otherwise there's really no reason to care too much about it.

Ziconic
  • 794
  • 6
  • 6