Archive for February 24, 2012

Friday, February 24, 2012

Creating Retain Cycles by Misusing Assertions

Evadne Wu (via Kevin Ballard):

When you use NSAssert, ultimately the expanded code contains a reference to self and _cmd, inside whatever method the line was used. This also prohibits use of NSAssert in a block, because it creates a retain cycle. Just use NSCAssert which looks slightly wonky but does not require being used within an Objective-C method, and does not allow the programmer to accidentally create retain cycles.