automatic-ref-counting

How do I avoid capturing self in blocks when implementing an API?

假装没事ソ 提交于 2019-11-26 00:49:41
问题 I have a working app and I\'m working on converting it to ARC in Xcode 4.2. One of the pre-check warnings involves capturing self strongly in a block leading to a retain cycle. I\'ve made a simple code sample to illustrate the issue. I believe I understand what this means but I\'m not sure the \"correct\" or recommended way to implement this type of scenario. self is an instance of class MyAPI the code below is simplified to show only the interactions with the objects and blocks relevant to

Why is @autoreleasepool still needed with ARC?

泪湿孤枕 提交于 2019-11-26 00:35:26
问题 For the most part with ARC (Automatic Reference Counting), we don\'t need to think about memory management at all with Objective-C objects. It is not permitted to create NSAutoreleasePool s anymore, however there is a new syntax: @autoreleasepool { … } My question is, why would I ever need this when I\'m not supposed to be manually releasing/autoreleasing ? EDIT: To sum up what I got out of all the anwers and comments succinctly: New Syntax: @autoreleasepool { … } is new syntax for

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

人盡茶涼 提交于 2019-11-26 00:22:57
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, how have you found it so far? Rob Napier There is no downside. Use it. Do it today. It is faster than your

Objective-C declared @property attributes (nonatomic, copy, strong, weak)

梦想的初衷 提交于 2019-11-26 00:10:41
问题 Can someone explain to me in detail when I must use each attribute: nonatomic , copy , strong , weak , and so on, for a declared property, and explain what each does? Some sort of example would be great also. I am using ARC. 回答1: This answer has numerous errors and is also outdated. Please see other questions/answers and the comments. Nonatomic nonatomic is used for multi threading purposes. If we have set the nonatomic attribute at the time of declaration, then any other thread wanting

Objective-C ARC: strong vs retain and weak vs assign

余生长醉 提交于 2019-11-25 23:42:21
问题 There are two new memory management attributes for properties introduced by ARC, strong and weak . Apart from copy , which is obviously something completely different, are there any differences between strong vs retain and weak vs assign ? From my understanding, the only difference here is that weak will assign nil to the pointer, while assign won\'t, which means the program will crash when I send a message to the pointer once it\'s been released. But if I use weak , this won\'t ever happen,

How to debug memory leaks when Leaks instrument does not show them?

自闭症网瘾萝莉.ら 提交于 2019-11-25 23:25:20
问题 I have an iOS app written in Swift that is leaking memory - in certain situation some objects should be released but they are not. I have learnt about the issue by simply adding deinit debug messages like this: deinit { println(\"DEINIT: KeysProvider released\") } So, the deinit message should be present in console after such events that should cause the object to release. However, for some of the objects that should be released, the message is missing. Still, Leaks Developer Tool does not

How does the new automatic reference counting mechanism work?

纵然是瞬间 提交于 2019-11-25 23:19:57
问题 Can someone briefly explain to me how ARC works? I know it\'s different from Garbage Collection, but I was just wondering exactly how it worked. Also, if ARC does what GC does without hindering performance, then why does Java use GC? Why doesn\'t it use ARC as well? 回答1: Every new developer who comes to Objective-C has to learn the rigid rules of when to retain, release, and autorelease objects. These rules even specify naming conventions that imply the retain count of objects returned from

Should IBOutlets be strong or weak under ARC?

萝らか妹 提交于 2019-11-25 22:04:29
问题 I am developing exclusively for iOS 5 using ARC. Should IBOutlet s to UIView s (and subclasses) be strong or weak ? The following: @property (nonatomic, weak) IBOutlet UIButton *button; Would get rid of all of this: - (void)viewDidUnload { // ... self.button = nil; // ... } Are there any problems doing this? The templates are using strong as are the automatically generated properties created when connecting directly to the header from the \'Interface Builder\' editor, but why? The

performSelector may cause a leak because its selector is unknown

ぃ、小莉子 提交于 2019-11-25 22:01:28
问题 I\'m getting the following warning by the ARC compiler: \"performSelector may cause a leak because its selector is unknown\". Here\'s what I\'m doing: [_controller performSelector:NSSelectorFromString(@\"someMethod\")]; Why do I get this warning? I understand the compiler can\'t check if the selector exists or not, but why would that cause a leak? And how can I change my code so that I don\'t get this warning anymore? 回答1: Solution The compiler is warning about this for a reason. It's very

Retained Core Foundation Property

吃可爱长大的小学妹 提交于 2019-11-25 15:18:30
(Xcode 4.2, iOS 5, ARC ) I have some properties of Core Foundation (/Graphics) objects that should take ownership of their objects. Now in these Apple docs I found this: In OS X v10.6 and later, you can use the __attribute__ keyword to specify that a Core Foundation property should be treated like an Objective-C object for memory management: @property(retain) __attribute__((NSObject)) CFDictionaryRef myDictionary; Unfortunately I couldn't find any elaboration on this. I'm using this: @property (nonatomic, strong) __attribute__((NSObject)) CGImageRef loupeImage; And it seems to work the way I'd