Search code examples
iosautomatic-ref-countingdelegation

Setting the modal view controller's delegate to nil with ARC


I'm writing app for iOS 4 with ARC. I'm presenting and dismissing modal view controllers through the standard delegate pattern. ARC in iOS 4 doesn't support weak references, so, I mark the child view controller's delegate property as assign. Should I set that delegate to nil in child view controller's dealloc method?


Solution

  • It shouldn't matter. Your child only uses the delegate to message the parent view controller. Your child view controller won't be making any calls to the parent after it is dealloc'ed, so you won't need to nil the delegate. By using assign or weak you haven't taken an ownership role with respect to the parent, so there is no need to nil the delegate for memory management.