stringWithFormat vs initWithFormat under ARC

automatic-ref-counting, cocoa, memory-management, nsstring, objective-c

Solution

With `ARC` enabled, these two methods are equivalent (i.e. `ARC` will auto-call `autorelease` method; always registering to nearest `@autoreleasepool`).

See:

- WWDC 2011 Session Video - Introducing Automatic Reference Counting

- WWDC 2011 Session Video - Objective-C Advancements In-Depth (explains how ARC code compiles)

Problem

`stringWithFormat:` is a class method of `NSString`, and returns an autoreleased string; `initWithFormat:` is an instance method, and before ARC the programmer had to take care of the returned object's memory management. If we have ARC turned on, what is the difference between the two methods?

Original source