Search code examples
iosobjective-ccocoaautomatic-ref-countingkey-value-observing

When calling dealloc from a UIView with ARC, can I assume ivars are still retained?


I am adding a KVO observer on a subclass of UIView to one of its subviews. I also have a strong reference to the subview. When I call removeObserver on the subview in dealloc, can I assume that the subview still exists? I don't want to leak the observer.

Basically, when dealloc is called in ARC, is the automatic call to [super dealloc] before or after this call?


Solution

  • From http://clang.llvm.org/docs/AutomaticReferenceCounting.html

    A class may provide a method definition for an instance method named dealloc. This method will be called after the final release of the object but before it is deallocated or any of its instance variables are destroyed. The superclass’s implementation of dealloc will be called automatically when the method returns.

    So [super dealloc] is called after calling the subclass dealloc implementation.