stringWithFormat vs initWithFormat under ARC

2020-07-17 06:04发布

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?

2条回答
The star\"
2楼-- · 2020-07-17 06:21
爷的心禁止访问
3楼-- · 2020-07-17 06:21

If ARC is turned on there should be no difference.

You would typically call initWithFormat: after you've allocated your NSString, so the retain count without ARC would be 1 greater than if you used the autoreleased class method to create your string (thus you would have to remember to release it).

With ARC, there is no difference, because retain/release/autorelease is completely handled for you.

查看更多
登录 后发表回答