ARC forbids autorelease?

后端 未结 4 2088
一向
一向 2020-12-22 07:56

New to ios and trying to return an NSString from an function. As I understand, I need to [NSString... alloc] init] in order to create the string for return. Al

4条回答
  •  长情又很酷
    2020-12-22 08:55

    Short answer is you don't! ARC will handle the memory management for you. When ARC is turned on, the compiler will insert the appropriate memory management statements such as retain and release messages.

    It is best to use ARC as the compiler has a better idea of an object's life cycle and is less prone to human error.

    One other important thing to note about ARC. ARC is not the same as traditional garbage collection. There is no separate process or thread running in the background, like java's GC, which deletes objects when there is no longer a reference to them. One could view ARC as compile time garbage collection :).

    The only other thing to be aware of is reference cycles and bridging pointers/objects between Objective-C and Obj-C++/C. You might want to look-up http://en.wikipedia.org/wiki/Weak_reference

    Hope this helps

提交回复
热议问题