automatic-ref-counting

Handling Pointer-to-Pointer Ownership Issues in ARC

馋奶兔 提交于 2019-11-26 03:48:18
问题 Suppose Object A has a property: @property (nonatomic, strong) Foo * bar; Synthesized in the implementation as: @synthesize bar = _bar; Object B manipulates a Foo ** , as in this example call from Object A : Foo * temp = self.bar; [objB doSomething:&temp]; self.bar = temp; Can this, or something similar, be done legitimately? What is the correct declaration for the doSomething: method? Furthermore, suppose Object B may be deallocated before I have a chance to set the bar property (and thus

Does ARC support dispatch queues?

拈花ヽ惹草 提交于 2019-11-26 03:32:23
问题 I\'m reading apple\'s documentation about \"Memory Management for Dispatch Queues\": Even if you implement a garbage-collected application, you must still retain and release your dispatch queues and other dispatch objects. Grand Central Dispatch does not support the garbage collection model for reclaiming memory. I know that ARC is not a garbage collector but I\'d like to be sure that I don\'t need to dispatch_retain and dispatch_release my dispatch_queue_t 回答1: The short answer: YES, ARC

What is the difference between a weak reference and an unowned reference?

与世无争的帅哥 提交于 2019-11-26 03:25:47
问题 Swift has: Strong References Weak References Unowned References How is an unowned reference different from a weak reference? When is it safe to use an unowned reference? Are unowned references a security risk like dangling pointers in C/C++? 回答1: Both weak and unowned references do not create a strong hold on the referred object (a.k.a. they don't increase the retain count in order to prevent ARC from deallocating the referred object). But why two keywords? This distinction has to do with the

Disable Automatic Reference Counting for Some Files

*爱你&永不变心* 提交于 2019-11-26 02:39:28
问题 I have downloaded the iOS 5 SDK and found that ARC is a great feature of the new Apple compiler. For the time being, many third party frameworks don\'t support ARC. Could I use ARC for my new code and keep the current retain/release code unchanged? The ARC converter doesn\'t work here, because some frameworks, such as JSONKit, cannot be converted to ARC by using the converter. Edit: The answer is to add -fno-objc-arc to the compiler flags for the files you don\'t want ARC. In Xcode 4, you can

Always pass weak reference of self into block in ARC?

孤者浪人 提交于 2019-11-26 02:25:46
问题 I am a little confused about block usage in Objective-C. I currently use ARC and I have quite a lot of blocks in my app, currently always referring to self instead of its weak reference. May that be the cause of these blocks retaining self and keeping it from being dealloced ? The question is, should I always use a weak reference of self in a block ? -(void)handleNewerData:(NSArray *)arr { ProcessOperation *operation = [[ProcessOperation alloc] initWithDataToProcess:arr completion:^

iOS app with ARC, find who is owner of an object

▼魔方 西西 提交于 2019-11-26 02:20:36
问题 I\'m writing an App that uses ARC and that seems to have some memory leaks at the moment. Googling I found some hints on how to use the Inspector. In there I can see heaps of allocations of instances of some classes and I can also see some call stack on how the object was allocated and how the retain count got changed. But it seems I can\'t see the complete call stack so I don\'t know who owns the object in the end. It looks to me that this owner is somehow not releasing the object (or the

How do I implement an Objective-C singleton that is compatible with ARC?

旧城冷巷雨未停 提交于 2019-11-26 01:44:19
问题 How do I convert (or create) a singleton class that compiles and behaves correctly when using automatic reference counting (ARC) in Xcode 4.2? 回答1: In exactly the same way that you (should) have been doing it already: + (instancetype)sharedInstance { static MyClass *sharedInstance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[MyClass alloc] init]; // Do any other initialisation stuff here }); return sharedInstance; } 回答2: if you want to create other

Sending an HTTP POST request on iOS

那年仲夏 提交于 2019-11-26 01:26:22
问题 I\'m trying to send an HTTP Post with the iOS application that I\'m developing but the push never reaches the server although I do get a code 200 as response (from the urlconnection). I never get a response from the server nor does the server detect my posts (the server does detect posts coming from android) I do use ARC but have set pd and urlConnection as strong. This is my code for sending the request NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL

How can I disable ARC for a single file in a project?

邮差的信 提交于 2019-11-26 01:17:48
问题 I am using ARC successfully in my project. However, I have encountered a few files (e.g., in unit tests and mock objects) where the rules of ARC are a little more fragile right now. I recall hearing that there was a way to disable ARC on a per-file basis, though I have been unable to find this option. Is this possible? How do I disable ARC on a per-file basis? 回答1: It is possible to disable ARC for individual files by adding the -fno-objc-arc compiler flag for those files. You add compiler

To ARC or not to ARC? What are the pros and cons? [closed]

*爱你&永不变心* 提交于 2019-11-26 01:06:13
问题 I\'ve yet to use ARC, since the majority of the code in the project I\'m working on at the moment was written pre-iOS 5.0. I was just wondering, does the convenience of not retaining/releasing manually (and presumably more reliable code that comes as a result?) outweigh any \'cost\' of using ARC? What are your experiences of ARC, and would you recommend it? So: How much benefit can ARC bring to a project? Does ARC have a cost like garbage collection in Java? Have you been using ARC and if so,