automatic-ref-counting

@autoreleasepool semantics

守給你的承諾、 提交于 2019-12-03 08:13:25
I was reading the ARC docs on the llvm site: http://clang.llvm.org/docs/AutomaticReferenceCounting.html#autoreleasepool ..in particular about @autoreleasepool. In lot of current implementation using NSAutoreleasePool, I see cases where the pool is drained periodically during a loop iteration - how do we do the same with @autorelease pool, or is it all done for us somehow under the hood? Secondly, the docs state that if an exception is thrown, the pool isn't drained.... ok exceptions are by name exceptional, but if they do happen, you might like to recover without leaking a load of memory. The

NSNotificationCenter removeObserver: in dealloc and thread-safety

≯℡__Kan透↙ 提交于 2019-12-03 07:52:43
问题 I'm using ARC and I'm calling [[NSNotificationCenter defaultCenter] removeObserver:someObserver]; in observer's dealloc . From NSNotificationCenter Class Reference Be sure to invoke this method (or removeObserver:name:object:) before notificationObserver or any object specified in addObserver:selector:name:object: is deallocated. NSNotificationCenter does not retain the observer. Q1: Is NSNotificationCenter thread-safe? In case, the observer is being deallocated(and removing observer from the

ARC App Crashes when accessing @property form ARC static lib

谁都会走 提交于 2019-12-03 07:24:02
I have a ARC ( automatic-reference-counting ) app that builds a static library (also ARC). The app will launch fine but when the an action is performed that reads or writes to a @property in the static library the app will crash with this error: dyld: lazy symbol binding failed: Symbol not found: _objc_setProperty_nonatomic Referenced from: /var/mobile/Applications/0E7ADBB4-FFE5-4CEB-B418-8A35A92E99D4/MyApp.app/MyApp Expected in: /usr/lib/libobjc.A.dylib dyld: Symbol not found: _objc_setProperty_nonatomic Referenced from: /var/mobile/Applications/0E7ADBB4-FFE5-4CEB-B418-8A35A92E99D4/MyApp.app

Breaking retain cycle with strong/weak self

强颜欢笑 提交于 2019-12-03 07:16:29
I've read posts about strong/weak self to break retain cycles but I am still confused as to how they work. I understand the use of __weak typeof(self) weakSelf = self to create a weak reference to self but I am confused about strong reference. As I understand it, the strong reference is so that there is a strong reference to self so that it doesn't get deallocated before the end of the block right? So why is it necessary to have __strong typeof(self) strongSelf = weakSelf ? Doesn't this end up pointing to the self object anyway? So why not just strongSelf = self ? Any non-weak object that you

How to enable ARC for a file in Non-ARC project?

烂漫一生 提交于 2019-12-03 06:36:12
问题 I know you can use -fno-objc-arc flag to disable ARC for files that NOT support ARC in an ARC project. Is there any way to enable ARC for files support ARC in a Non-ARC project? Thanks! 回答1: Yup: add the -fobjc-arc flag the same way. 来源: https://stackoverflow.com/questions/11255177/how-to-enable-arc-for-a-file-in-non-arc-project

What is the equivalent of @autoreleasepool in Swift?

隐身守侯 提交于 2019-12-03 06:26:25
问题 In Swift, I notice there is no @autoreleasepool{} construct, although Swift does use ARC. What is the proper way to manage an autoreleasepool in Swift, or has it been removed for some reason? 回答1: This is explained in detail in WWDC 2014 session video number 418 "Improving Your App with Instruments", which you can also download as a PDF. But in short, the syntax is: autoreleasepool { /* code */ } 回答2: Just FYI, Xcode constructed the full code as follows: autoreleasepool({ () -> () in // code

Need Reachability version for ARC in iOS5

半世苍凉 提交于 2019-12-03 06:23:07
问题 Using Apple's Reachability code in iOS5 I get a bunch of compilation errors as shown below. Any ideas on what is happening here? I'm using ARC so I have edited the standard code slightly to remove autorelease/retain and the NSAutoReleasePool . Undefined symbols for architecture armv7: "_SCNetworkReachabilityCreateWithAddress", referenced from: +[Reachability reachabilityWithAddress:] in Reachability.o "_SCNetworkReachabilityCreateWithName", referenced from: +[Reachability

ld: duplicate symbol _objc_retainedObject on iOS 4.3 , but not on iOS 5.0

假装没事ソ 提交于 2019-12-03 05:55:27
Some background - I've built a custom Framework using Diney's guide at http://db-in.com/blog/2011/07/universal-framework-iphone-ios-2-0/ Its built for both armv6 / armv7 , its an ARC-based framework, compiled with a depolyment target of 4.3. When i put the resulting framework in a 5.0 project it works great, but when i put it in a 4.3 project (ARC or non-arc, doesnt matter), i get the following which i can't really understand ... I've also tried adding libarclite.a manually but it didn't change anything. ld: duplicate symbol _objc_retainedObject in /Users/freak4pc/Project/MyFramework.framework

What are the new type qualifiers introduced with ARC?

落爺英雄遲暮 提交于 2019-12-03 05:53:31
问题 Automatic Reference Counting (ARC) introduces some new type qualifiers. I've seen __strong and __weak , but what do they do? 回答1: __strong means that on assignment, the rvalue of the expression will be retained and stored into the lvalue using primitive semantics. (To deallocate such an object, all you must do is assign it nil , the previously referenced object will be released, nil will be retained, which effectively does nothing and it's peaches and cream.) __unsafe_unretained and __weak

After Auto-ARC Conversion: Assigning retained object to unsafe property; object will be released after assignment

拜拜、爱过 提交于 2019-12-03 05:36:07
问题 I just converted an old project to ARC using Xcode's automatic refactoring. @property (nonatomic, retain) NSMutableArray *cards; was replaced by: @property (nonatomic) NSMutableArray *cards; This makes sense because what I've read is that "strong" is the default state. However, the following line is giving me the error in the title: self.cards = [[NSMutableArray alloc] initWithCapacity:54]; The error is solved by adding strong back in where retain used to be: @property (nonatomic, strong)