Managing iPhone memory with viewDidUnload

If you set the nil property to viewDidUnload, do you need to free it again in dealloc?

+3
source share
1 answer

No, but:

  • You do not need to check this case. [nil release]fine.
  • You cannot count on a call viewDidUnload.

So just let it go as usual at -dealloc.

Of course, you must make sure that you really released the previous object. You implicitly do this if you use a synthesized setter:

self.myProperty = nil;  // good
// or
[self setMyProperty:nil]; // also good

But installing ivar on nil will proceed:

self->myProperty = nil; // leaky as a sieve
// or 
myProperty = nil; // as useful as a screen door on a submarine

These are common mistakes.

, nil -dealloc - . , KVO. dealloc: release, ? .

+4

Source: https://habr.com/ru/post/1759827/


All Articles