automatic-ref-counting

Breaking retain cycle with strong/weak self

核能气质少年 提交于 2019-12-20 21:49:10
问题 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

NSInvocation and ARC (Automatic Reference Counting)

我们两清 提交于 2019-12-20 20:19:34
问题 When trying to migrate my current code to ARC, I'm getting errors whenever I pass an NSString as an NSInvocation argument. Example: NSInvocation inv = ...; NSString *one = @"Hello World!"; [inv setArgument:&one atIndex:2]; The error happens when I use the Refactor -> Convert to Objective-C ARC option from the Edit menu. The text is "NSInvocation's setArgument is not safe to be used with an object with ownership other than __unsafe_retained." How would I get around this? 回答1: This might work;

IBOutlet for NSTextView in a ARC project

孤街醉人 提交于 2019-12-20 17:26:10
问题 As you read here in most cases a IBOutlet should be weak. Now as you can read in the development library not all classes support weak references. (e.g. NSTextView). This means you have to use assign: @property (assign) IBOutlet NSTextView *textView; If you use a weak reference you will get the following error: "Synthesis of a weak-unavailable property is disallowed because it requires synthesis of an ivar of the __weak object" What the documentation missed to mention is now you have to set

Weak and strong properties in -viewDidUnload under ARC

蓝咒 提交于 2019-12-20 14:15:31
问题 I am new to iphone development . I am using ARC for my project. As far as I understood using ARC we don't have to release any object manually. But , I have observed in some places , people explicitly set their object to nil in the ViewDidUnload even after using ARC. For example, in .h file I have something like this: @property (unsafe_unretained, nonatomic) IBOutlet MKMapView *mapViewOutlet; @property (unsafe_unretained, nonatomic) IBOutlet UIToolbar *toolBar; @property (strong,nonatomic)

ARC, self and blocks

旧巷老猫 提交于 2019-12-20 12:39:27
问题 I thought I understood the usage of self in a block that is copied is a no no . But in an attempt to clean my code i enabled a bunch of warnings in Xcode, one called "Sending messages to weak pointers" so now in all my blocks, every time I use my created weakself reference __weak typeof(self) weakself = self; I get this warning: Weak receiver may be unpredictably set to nil a trivial example: __weak typeof(self) weakself = self; [aClass doSomethingInABlock:^{ [weakself doSomething]; //warning

Are there any concrete study of the performance impact of using ARC?

依然范特西╮ 提交于 2019-12-20 12:25:33
问题 I could not find an objective study regarding ARC performance impact in a real life project. The official doc says The compiler efficiently eliminates many extraneous retain/release calls and much effort has been invested in speeding up the Objective-C runtime in general. In particular, the common “return a retain/autoreleased object” pattern is much faster and does not actually put the object into the autorelease pool, when the caller of the method is ARC code. which has been relayed

AVPlayer continues to play after ViewController is removed from NavigationController

偶尔善良 提交于 2019-12-20 10:04:28
问题 So I'm using ARC in my project and when I add an AVPlayerLayer it works just fine and dandy, but when I pop the UIViewController from my UINavigationItem the video continues to play in the background. Does anyone know how you would handle this? It seems like something easy I'm just overlooking. Here's the code I have for the initially instantiations. self.currentItem = [[AVPlayerItem alloc] initWithURL:url]; self.player = [[AVPlayer alloc]initWithPlayerItem:self.currentItem]; self

Messaging a __weak object?

断了今生、忘了曾经 提交于 2019-12-20 09:57:52
问题 What happens if I send a message to a weak object? Does sending the message possess the object and hold it in memory until return? I'm thinking of this pattern: __weak MyObject *weakSelf = self; dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf doSomeAction]; }); Assuming weakSelf is non-nil when the message is sent, might it be deallocated while doSomeAction is working or is it guaranteed to remain valid until doSomeAction returns? 回答1: From the Clang ARC documentation: Reading occurs

Sudzc with iOS 5 and ARC

丶灬走出姿态 提交于 2019-12-20 09:43:17
问题 I've been trying to get a webservices working using Sudzc. Whenever I convert my WSDL to obj-c without automatic reference counting it works just fine. The problem is, we are building all our applications in iOS 5 now and all our code uses ARC. Sudzc now also allows you to create a bundle with ARC enabled but when I run this code it always returns null. I tried debugging the Sudzc code and it does receive a correct xml response back from the service. Somewhere something is lost in translation

Do I need use dealloc method with ARC?

偶尔善良 提交于 2019-12-20 09:27:50
问题 So, I have class: @interface Controller : NSObject { UILabel* fileDescription; } @property(strong, nonatomic) UILabel* fileDescription; Do I need use method dealloc where property fileDescription will equal nil? For example: -(void)dealloc { fileDescription = nil; } If not, who will dismiss memory used by fileDescription? 回答1: Generally you don't need to provide a subclassed dealloc method as ARC manages the lifetime of the instance variables. However it can be useful to perform clean-up