automatic-ref-counting

In ARC do we need to send removeObserver: explicitly?

随声附和 提交于 2019-11-29 03:23:21
Do we have to send removeObserver: explicitly for objects that have been added as observers to an NSNotificationCenter before? I am bit confused and unable to find the exact answer for this. Please provide me in detail, about this including why we need to removeObserver explicitly, and why don't compiler put it implicitly in class/application? rckoenes Yes, you need to call removeObserver: , if you don't the observed class could call all deallocated instance of the observer. From 10.11 observers are not required to un-register in their deallocation method. NSNotificationCenter and

Is self.iVar necessary for strong properties with ARC?

喜你入骨 提交于 2019-11-29 03:17:47
If I declare a property strong, like so: @property (strong, nonatomic) UIView *iVar; When I'm setting it, does it matter if I do iVar = ... or self.iVar = ... ? It seems that with ARC, they do the same thing. If I only declare the instance variable (not the @property), e.g., BOOL selected , does that mean it's inferred to be __unsafe_unretained (since there's no property specifying it to be strong), or must I explicitly specify that? It seems like I may have answered my own questions above in answering ARC: How to release static variable? , but I'm still slightly confused on the above

when should you use __bridge vs. CFBridgingRelease/CFBridgingRetain?

我怕爱的太早我们不能终老 提交于 2019-11-29 03:09:19
I have this code that uses "__bridge" to cast the ids of colors: CGColorRef tabColor = (5 == 5 ? [UIColor blueColor].CGColor : [UIColor greenColor].CGColor); CGColorRef startColor = [UIColor whiteColor].CGColor; CGColorRef endColor = tabColor; NSArray *colors = [NSArray arrayWithObjects:(__bridge id)startColor, (__bridge id)endColor, nil]; CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)colors, locations); but would: NSArray *colors = [NSArray arrayWithObjects:(id)CFBridgingRelease(startColor), (id)CFBridgingRelease(endColor), nil]; CGGradientRef gradient =

ARC error : -fobjc-arc is not supported with fragile abi [duplicate]

血红的双手。 提交于 2019-11-29 02:56:36
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Objective-C ARC Error: -fobjc-arc is not supported with fragile abi Clang LLVM 1.0 Error error: -fobjc-arc is not supported with fragile abi I'm buildin an OSX app and I get the same error when I compile it with "Profile", to work with Instruments. Any idea how to solve it? 回答1: ARC is only available to 64-bit applications in OS X. Therefore, you must set your application's architecture to "64-bit Intel" in the

With ARC why use @properties anymore?

感情迁移 提交于 2019-11-29 02:50:57
问题 In non-ARC code retained properties handily take care of memory management for you using the self.property = syntax, so we were taught to use them for practically everything. But now with ARC this memory management is no longer an issue, so does the reason for using properties evaporate? is there still any good reason (obviously other than providing public access to instance variables) to use properties anymore? 回答1: But now with ARC this memory management is no longer an issue, so does the

Weak object in an NSDictionary?

杀马特。学长 韩版系。学妹 提交于 2019-11-29 02:48:53
问题 I would like to store a zeroing weak reference to an object in a NSDictionary . This is for a reference to a parent NSDictionary , so I can crawl back up a large structure without searching. I can not use __weak here; even if my local reference is weak, the NSDictionary will store a strong reference to the object that was weakly referenced. And, of course, NSDictionary can't have nil objects. I'm on iOS, not Mac, so NSHashTable isn't available. And I only want one object to be weak; the rest

Error compiling with ARC when runtime programming dynamic method

自闭症网瘾萝莉.ら 提交于 2019-11-29 02:38:36
I am trying to do some runtime programmation on Objective-C. In order to do this I override the resolveClassMethod method. Unfortunately I come up with some compilation error with clang when ARC is active : error: no known class method for selector 'dynamic' Everything works fine if I use gcc or clang without ARC ( -fno-objc-arc option passed), except a warning instead of the error. I am aware that ARC need to know the name of the method called to figure out how to manage the memory with returned value (following method name convention). But how to this issue without an ugly performSelector

How does my ARC app work in iOS 3.x?

天涯浪子 提交于 2019-11-29 02:20:15
So I just found out that ARC is only supported for devices running iOS 4.0+. How does my app (in the store) work on devices running iOS 3.0 then (definitely using ARC)? I'm so confused. Solution from below: As long as I don't use zeroing weak references it seems that using ARC still works with iOS 3.x, but Apple just has not guaranteed the result. ARC is mostly a compile time feature, the compiler inserts the appropiate release calls. AFAIK only zeroing weak references need runtime support. So as longs as you don't use those you're on thin ice, but it can work. Because ARC works at compile

UIPageViewController crashes when flipped too fast during low memory

烂漫一生 提交于 2019-11-29 02:10:47
问题 I had some memory problems due to Xcode's template for a UIPageViewController caching all the page data, so I changed it to load the pages dynamically, so now when my app receives a low memory warning, it releases the memory for page's not showing, but if the user is flipping through the pages real fast by tapping the edge of the screen, it still crashes. I'm guessing this is because it can't free the memory fast enough when didReceiveMemoryWarning gets called. If the user is flipping slowly,

Do capture lists of inner closures need to redeclare `self` as `weak` or `unowned`?

喜夏-厌秋 提交于 2019-11-29 02:07:41
If I have a closure passed to a function like this: someFunctionWithTrailingClosure { [weak self] in anotherFunctionWithTrailingClosure { [weak self] in self?.doSomething() } } If I declare self as [weak self] in someFunctionWithTrailingClosure 's capture list without redeclaring it as weak again in the capture list of anotherFunctionWithTrailingClosure self is already becoming an Optional type but is it also becoming a weak reference as well? Thanks! The [weak self] in anotherFunctionWithTrailingClosure is not needed. You can empirically test this: class Experiment { func