+[NSString stringWithString:] — what's the point?

后端 未结 7 1754
悲&欢浪女
悲&欢浪女 2020-12-01 16:20

As NSString strings are immutable, what is the value of the stringWithString: class method?

I get the utility when used with NSMutabl

相关标签:
7条回答
  • 2020-12-01 16:59

    FYI, now that we are compiling with ARC enabled, you don't have to manually release at all, ARC will insert the release calls during compile time. So how is it still different? stringWithString is still added to the autorelease pool which gets drained sometime in the future (unless you created your own autorelease pool). initWithString will have a release call right before the function ends, so if you didn't retain it somewhere in the method, you can be sure that the string is destroyed by the end of the function call. This gives you a tighter control on the memory management as opposed to using autoreleased objects.

    0 讨论(0)
提交回复
热议问题