Yes, stringWithFormat returns an autoreleased NSString.

I ran into an interesting problem today. It was really basic and embarassing, so naturally I figured I’d go public with it…

Typically I use the allocinitWithFormatrelease way of creating strings, but today I used the NSString stringWithFormat factory method to generate a new NSString. Of course at the end of my method that was using the string I released the variable and it caused a mini-meltdown in the app I was working on.

So the new thing I found out today (and I guess I didn’t realize before) is that stringWithFormat returns an autoreleased NSString.

This forum post from 2008 just confirms it:

NSString: Differences between initWithFormat and stringWithFormat

Be careful out there!