automatic-ref-counting

Dealloc not being called on ARC app

99封情书 提交于 2019-11-28 03:34:20
I have a UIViewController that is pushed onto a container controller and then popped off, and using the allocations instrument, I can see that the view controller is destroyed afterwards. However, a breakpoint in the controller's dealloc is never reached. Does anyone know why dealloc isn't called? Is it possible for ARC to destroy an object without calling dealloc? Also, I've disabled NSZombies (some have said that can cause dealloc not to fire). Edit: Dealloc doesn't do much, just prints to the console, and it never gets called: - (void)dealloc { NSLog(@"Deallocating..."); } I can't post the

Find where object is retained with ARC

我的梦境 提交于 2019-11-28 03:12:15
I have an object that is being retained more than necessary (most likely due to a property that is strong instead of weak ). Big codebase, so it's hard to find where. How can I find all the lines in which this object is being retained when using ARC? If I weren't using ARC I guess I could simply override retain and check from where it's called. Can I do something similar with ARC? bbum To track growth of an application, Heapshot Analysis has proven very effective. It will capture both true leaks and accretion of memory where the allocations are not accounted for by leaks. You can see all of

How do I verify reference count in ARC mode?

≡放荡痞女 提交于 2019-11-28 03:09:05
I used to verify that some of my variables had the expected retain count using [myVar retainCount] under the debugger, especially for var that did not have a custom dealloc. How do you do this in ARC mode? How do you ensure that there are no memory leaks? Note: I understand that ARC should handle this for me, but life is far from being perfect, and in real life you have objects that are sometimes allocated by third party libraries (using retain?) and never deallocated. Image that I do this: MyObj *myObj=[[MyObj alloc] init]; then I call [somethingElse doSomethingWithMyObj:myObj]; and later, I

Generic typeof for weak self references

久未见 提交于 2019-11-28 03:09:04
I am trying to figure out a way to use typeof to create a weak reference to self for use in blocks to avoid retain cycles. When I first read about this it seems that the convention was to use __block typeof(self) bself = self; , which compiles but using __block to avoid retain cycles doesn't work anymore and __weak should be used instead. However __weak typeof(self) bself = self; results in an error: The type 'typeof (self)' (aka 'TUAccountsViewController *const __strong') already has retainment attributes set on it Is there a way to use typeof or another call to generically create a weak

How do I replace weak references when using ARC and targeting iOS 4.0?

a 夏天 提交于 2019-11-28 02:48:52
I've begun developing my first iOS app with Xcode 4.2, and was targeting iOS 5.0 with a "utility application" template (the one that comes with a FlipsideViewController). I read that since ARC is a compile-time feature, it should be compatible with iOS 4 as well, so I attempted to target my app to 4.3, and try compiling it. When I do so, I get this error: FlipsideViewController.m: error: Automatic Reference Counting Issue: The current deployment target does not support automated __weak references It is referencing this line: @synthesize delegate = _delegate; That variable is declared as:

What does the “strong” keyword do

旧街凉风 提交于 2019-11-28 02:36:47
问题 I downloaded the Xcode 4.2 developer preview version and I created a cocoa application. But I found a very weird syntax in the delegate class: @property (strong) IBOutlet NSWindow *window; What does this mean? And the compiler can't even compile it. Thanks in advance! 回答1: It indicates that this property is a strong relationship—an ownership. It's ARC's version of the retain keyword in the same context. And the compiler can't even compile it. It's valid ARC code, so if your tools support ARC,

Storing email in keychain impossible (KeychainItemWrapper)

扶醉桌前 提交于 2019-11-28 02:35:10
问题 I'm using the ARCified version of KeychainItemWrapper available at github, and I can't get it to store both email and password. KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"myApp" accessGroup:@"MY_APP.com.yourcompany.GenericKeychainSuite"]; [keychainItem setObject:[self.email dataUsingEncoding:NSUTF8StringEncoding] forKey:(__bridge id)kSecAttrAccount]; [keychainItem setObject:self.password forKey:(__bridge id)kSecValueData]; I works perfectly as long

Semantic Issue: Property's synthesized getter follows Cocoa naming convention for returning 'owned' objects

馋奶兔 提交于 2019-11-28 02:32:01
I'm currently using the iOS 5 SDK trying to develop my app. I'm trying to make an NSString a property, and then to synthesize it in the .m file (I have done this before with no issues). Now, I came across this: "Semantic Issue: Property's synthesized getter follows Cocoa naming convention for returning 'owned' objects." This is my code: .h @interface ViewController : UIViewController { NSString *newTitle; } @property (strong, nonatomic) NSString *newTitle; .m @synthesize newTitle; Does anyone have a clue how I could fix this? Thanks!! My guess is that the compiler version you’re using follows

How to automatically convert Manual Retain-Release code to ARC?

白昼怎懂夜的黑 提交于 2019-11-27 23:10:46
I have thousands of line of code written for iOS 4. The codebase contains many calls to retain and release , which cause errors when the project is updated to iOS 5 and ARC. Is there a way to automatically convert Manual Retain-Release (MRR) code to Automatic Reference Counting (ARC)? In Xcode 6+, the command is now: Edit > Convert > To Objective-C ARC... From the Xcode 4.2 release notes : To initiate the process, enable Continue building after errors in the General Preferences pane, then choose Edit > Refactor > Convert to Objective-C ARC . The targets that you convert are updated to build

What is the proper way to avoid Retain Cycle while using blocks

给你一囗甜甜゛ 提交于 2019-11-27 22:23:01
What is the proper way to add objects in NSMutableArray which is strongly defined by property. [tapBlockView setTapBlock:^(UIImage* image) { [self.myImageArray addObject:image]; // self retain cycle } If I will create weak reference something like __weak NSMutableArray *array = self.myImageArray; [tapBlockView setTapBlock:^(UIImage* image) { [array addObject:image]; // If I will do this then how will I update original Array ? } I have also tried __weak id weakSelf = self; [tapBlockView setTapBlock:^(UIImage* image) { [weakSelf storeImageInaNewMethod:image]; // Calling SToreImageInaNewMethod }