automatic-ref-counting

iPhone ARC Release Notes - dealloc on system classes delegates?

限于喜欢 提交于 2020-01-06 05:02:48
问题 I understand the ARC Release Notes, however I have been wondering what does this mean exactly and what are the system classes: You may implement a dealloc method if you need to manage resources other than releasing instance variables. You do not have to (indeed you cannot) release instance variables, but you may need to invoke [systemClassInstance setDelegate:nil] on system classes and other code that isn’t compiled using ARC. This is right here ARC Release Notes under the new rules enforced

How ARC works when using third library code?

依然范特西╮ 提交于 2020-01-05 19:14:11
问题 I was reading article related to ARC.Following is the section: ARC also taps into a the Objective-C language naming conventions and infers the ownership of the returned object. In Objective-C, a method that stats with any one of the following prefix alloc, copy, mutableCopy and new are considered to be transferring ownership of the returned object to the caller. This means, in your application, when you create a method, ARC automatically infers whether to return a autoreleased object or a +1

Navigation arc memory not released

巧了我就是萌 提交于 2020-01-05 19:10:52
问题 I have two table table controllers A and B. A has a list of items and when an item is clicked, it pushes to B. The problem is that when B was shown, the instrutment indicated a live memory increase, but it did not decreased when I clicked on back button. The dealloc method in B was executed but the memory seemed changed slightly. I checked that B was not retained anywhere else so what may the reasons that can cause this problem? In B, there are many textfields, labels which are nonatomic and

How to efficiently reference count cons cells (detecting cycles)?

一世执手 提交于 2020-01-05 08:37:33
问题 I need to make some sort of liblisp (in C11), and it will need to handle the basic functions, pretty much like what libobjc does for the Objective-C language. Edit I'm rewritting the question to something less generic. I got an implementation like this: typedef struct cons { void *car, *cdr; } *cons_t; cons_t cons_init(void *, void *); void *cons_get_car(cons_t); void *cons_get_cdr(cons_t); void cons_set_car(cons_t, void *); void cons_set_cdr(cons_t, void *); void cons_free(cons_t); bool cons

Can't Build in Xcode 6 - ARC Issues in Apple Frameworks

流过昼夜 提交于 2020-01-05 04:37:08
问题 Upon updating to Xcode 6, I can no longer build my app. Xcode is throwing errors and warnings like the following: Error: /Applications/Xcode-6.0.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/ CoreData.framework /Headers/ NSManagedObjectContext .h:121:5: Pointer to non-const type 'id' with no explicit ownership Warning: /Applications/Xcode-6.0.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System

Strange “mutating method sent to immutable object” error when adding an object to a mutable array

纵饮孤独 提交于 2020-01-04 21:16:45
问题 This is a strange one... Periodically I am checking if the user has achieved a new top score in my app. Here is my code: - (void) newTopScore { // pull old top score from the database NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSDictionary *getBoardsAndScores = [defaults dictionaryRepresentation]; NSMutableArray *boardsAndScores = [[getBoardsAndScores objectForKey:@"boardsAndScores"] mutableCopy]; NSMutableDictionary *boardAndScoreObject = [[boardsAndScores

Why does Apple use assign rather than weak to store a delegate?

心已入冬 提交于 2020-01-04 10:19:00
问题 Some Cocoa and Cocoa Touch classes declare their delegate properties as assign rather than weak , which forces users of the class to nil out the property in dealloc -(void)dealloc { self.imageScrollView.delegate = nil; self.tableView.delegate = nil; self.tableView.dataSource = nil; } Which is very cumbersome. Why would Apple do it this way? 回答1: The reason why is that not all system classes have been compiled with ARC. You may implement a dealloc method if you need to manage resources other

Why does Apple use assign rather than weak to store a delegate?

走远了吗. 提交于 2020-01-04 10:18:08
问题 Some Cocoa and Cocoa Touch classes declare their delegate properties as assign rather than weak , which forces users of the class to nil out the property in dealloc -(void)dealloc { self.imageScrollView.delegate = nil; self.tableView.delegate = nil; self.tableView.dataSource = nil; } Which is very cumbersome. Why would Apple do it this way? 回答1: The reason why is that not all system classes have been compiled with ARC. You may implement a dealloc method if you need to manage resources other

How can the Objective-C runtime know whether a weakly referenced object is still alive?

老子叫甜甜 提交于 2020-01-04 06:50:14
问题 With the advent of ARC, some new functions were made available to allow developers to play around with weakly referenced objects. id objc_loadWeak(id *location) is one of them. This function receives one parameter correspoding to a location in memory where a weak object was stored and returns this object if it is still alive or nil if it were deallocated. It seems that when an object obj is stored as weak in a location location with id objc_storeWeak(id *location, id obj) , obj is put in a

Core Data : inserting Objects crashed in global queue [ARC - iPhone simulator 6.1]

守給你的承諾、 提交于 2020-01-04 06:23:28
问题 I have a very simple Core Data demo, in which there is only one button. When I click the 'run' button, the App creates 10,000 objects in a for-loop, which is running in the global queue . Update for more detail : If I put the for-loop in main thread, it runs well. Update for my intent : I know that MOC is not thread-safe, but according to the Apple doc, we can also use serial queue to access the MOC, and the serial queue uses more than one threads. Here I create the Core Data stack: #pragma