automatic-ref-counting

ARC memory leaks

拜拜、爱过 提交于 2019-11-27 03:54:11
I am experiencing memory leaks linked to NSMutableArray's in a project configured to use ARC, which I thought was supposed to handle these things for you. The following code is triggering leaks of NSNumbers: NSMutableArray *myArray = [[NSMutableArray alloc] init]; NSNumber *myNumber = [NSNumber numberWithFloat:10]; [myArray addObject:myNumber]; Running the last line gives the following in the debugger: objc[1106]: Object 0x765ffe0 of class __NSCFNumber autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug Aside from that, the object appears to be

How to enable ARC for a single file

末鹿安然 提交于 2019-11-27 03:47:55
I want to bring a single Objective-C class written using ARC into an old project. The internet provides many references for how to enable ARC for your project and then disable it for single files but I want to do the opposite. I want to leave the project as it is, i.e. using manual reference counting, and then enable ARC just for the new file. (My searches have failed me here.) Is this possible? How? Add the -fobjc-arc flag to any files for which you'd like to enable ARC, as described in the ARC documentation . Select Target > Build Phases > Compile Source > Select Your class > Double Click >

Is “self” weak within a method in ARC?

吃可爱长大的小学妹 提交于 2019-11-27 03:37:52
问题 I have a method that occasionally crashes. -(void)foo{ [self doSomething]; [self.delegate didFinish]; [self doSomethingElse]; } -doSomething works correctly, then I call to a delegate -didFinish. Within -didFinish, the reference to this object might be set to nil, releasing it under ARC. When the method crashes, it does so on -doSomethingElse. My assumption was that self would be strong within a method, allowing the function to complete. Is self weak or strong? Is there documentation on this?

How to disable Xcode4.2 Automatic Reference Counting

时光毁灭记忆、已成空白 提交于 2019-11-27 03:37:39
Today, I have update my xCode to 4.2 version, And I want to disable the ARC, I also search with the google. but can't fix my problem. According the search results, In the target setting, I can't find the 'Objective-C Automatic reference counting' item, So have no chance to set it to NO. I find the item one by one, and also use the search field. And one know the newest Xcode4.2 ,how to disable the ARC for the project, not for the specific file. Thanks very much. NJones Click on you project, in the left hand organizer. Select your target, in the next column over. Select the Build Settings tab at

Why is object not dealloc'ed when using ARC + NSZombieEnabled

安稳与你 提交于 2019-11-27 03:34:30
I converted my app to ARC and noticed that an object alloc'ed in one of my view controllers was not being dealloc'ed when that view controller was dealloc'ed. It took a while to figure out why. I have Enable Zombie Objects on for my project while debugging and this turned out to be the cause. Consider the following app logic: 1) Users invokes action in RootViewController that causes a SecondaryViewController to be created and presented via presentModalViewController:animated . 2) SecondaryViewController contains an ActionsController that is an NSObject subclass. 3) ActionsController observes a

KVO and ARC how to removeObserver

天涯浪子 提交于 2019-11-27 03:08:29
How do you remove an observer from an object under ARC ? Do we just add the observer and forget about removing it? If we no longer manage memory manually where do we resign from observing? For example, on a view controller: [self.view addObserver:self forKeyPath:@"self.frame" options:NSKeyValueObservingOptionNew context:nil]; Previously, I would call removeObserver: in the view controller's dealloc method. You still can implement -dealloc under ARC, which appears to be the appropriate place to remove the observation of key values. You just don't call [super dealloc] from within this method any

Property vs. ivar in times of ARC

余生长醉 提交于 2019-11-27 03:00:48
It is my understanding that setting an ivar now retains the object being assigned to it, since setting variables defaults to the strong qualifier. Because ivars are in the scope of the object they are declared in and strong retains objects within the scope of the variable, this means the ivars value would never be released while the object containing the ivar is still alive. Is this correct? If so, am I right in thinking that there is, in terms of memory management, no difference between a retaining (strong) property and a simple ivar anymore? If a variable: Is declared in a class using ARC .

When converting a project to use ARC what does “switch case is in protected scope” mean?

扶醉桌前 提交于 2019-11-27 02:40:45
When converting a project to use ARC what does "switch case is in protected scope" mean? I am converting a project to use ARC, using Xcode 4 Edit -> Refactor -> Convert to Objective-C ARC... One of the errors I get is "switch case is in protected scope" on "some" of the switches in a switch case. Edit, Here is the code: the ERROR is marked on the "default" case: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @""; UITableViewCell *cell ; switch (tableView.tag) { case 1: CellIdentifier = @"CellAuthor";

Weak and strong property setter attributes in Objective-C

ぐ巨炮叔叔 提交于 2019-11-27 02:36:47
What is the difference between weak and strong property setter attributes in Objective-C? @property(retain, [weak/strong]) __attribute__((NSObject)) CFDictionaryRef myDictionary; What is the impact and benefit? I heard that weak is not available on iOS 4 and we need to use assign. Is weak similar to assign? You either have ARC on or off for a particular file. If its on you cannot use retain release autorelease etc... Instead you use strong weak for properties or __strong __weak for variables (defaults to __strong ). Strong is the equivalent to retain, however ARC will manage the release for

Starting with Objective-C: To ARC or not to ARC?

﹥>﹥吖頭↗ 提交于 2019-11-27 02:20:39
问题 According to Apple's ARC Documentation, there are a fairly significant number of changes to the way that one develops software when using ARC. As a complete beginner to Objective-C, would it be better to start off with ARC disabled, with the idea that it would give me a better low-level understanding of what is going on behind the scenes? Or has ARC essentially deprecated the 'old way' of doing things, to the point that it's not really worth spending time learning? 回答1: This is basically an