automatic-ref-counting

ARC Autoreleased with no pool in place

百般思念 提交于 2019-12-10 11:58:05
问题 I am using ARC in my code and I am getting the error Object 0x781b8e0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug The line it breaks on is return UIApplicationMain(argc, argv, nil, NSStringFromClass([HomePageAppDelegate class])); Since I am using ARC I cannot put an NSAutoReleasePool around it like I usually would. What can I use in order to fix this error? 回答1: use this on the line where it showing the warning

ARC: Getting EXC_BAD_ACCESS from inside block used in delegate method

馋奶兔 提交于 2019-12-10 11:23:55
问题 I must be doing something wrong, but the Automatic Reference Counting docs don't give me a hint on what it might be. What I'm doing is calling a method with a block callback from inside a delegate method. Accessing that same delegate from inside the block results in a bad access . The problem is the object I'm passing - loginController which is sending the message to its delegate - is clearly not released, when I don't access it inside the block I can call the method multiple times without an

Message sent to deallocated instance with ARC using custom getter and setter

喜欢而已 提交于 2019-12-10 11:18:55
问题 I'm trying to implement a custom getter and setter for my custom object HFObject and my app crashed with a Message sent to deallocated instance error despite using ARC. I've read every single related post, the ones that were written pre-ARC don't apply, and everything else didn't help. I have the zombie object debugger option turned on. Setting up the custom HObject Within HObject.h I have declared these four properties: @property (retain) NSString *email; //Will use custom getter/setter

ARC and releasing object created in method

大憨熊 提交于 2019-12-10 11:14:58
问题 I have stumbled upon an issue for which I can't find answer elsewhere. When I am calling a method which returns pointer to an object which is later used and at the end set to nil, it is still allocated in memory (according to Instruments). I'm using XCode 4.6.3 and iOS 6.1. ARC is turned on. Here is sample code: ClassA.h @interface ClassA : NSObject -(void)runSomething; @end ClassA.m #import "ClassA.h" #import "ClassB.h" @implementation ClassA -(void)runSomething { int counter = 0; while

iPhone Reachable classes

时光总嘲笑我的痴心妄想 提交于 2019-12-10 11:04:43
问题 I have added the two files Reachability.h/m. The problem I am having is in the ReachabilityCallback method NSCAssert([(NSObject*) info isKindOfClass: [Reachability class]], @"info was wrong class in ReachabilityCallback"); The error message is: Cast of C pointer type 'void *' to Objective-C pointer type 'NSObject * requires a bridged cast NSAutoreleasePool* myPool = [[NSAutoreleasePool alloc] init]; Error: 'NSAutoreleasePool' is unavailable: not available in automatic reference counting mode

When to use strong or weak for properties

妖精的绣舞 提交于 2019-12-10 10:53:14
问题 I have a table view as an IBOutlet , and by default XCode sets its property to be strong rather than weak . Sometimes I get a "recieved memory warning" message. So I tried to change many properties from strong to weak , but it doesn't seem to affect the process and things work smoothly. Should I set the outlets to weak, or am I wrong? And most importantly, should I set ALL properties to nil in the viewDidUnload method, or only the IBOutlet s? 回答1: You should set only Strong properties to nil

difference between _var and self.var

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 10:12:38
问题 With all this new ARC stuff (which does not fall under NDA…) coming out, it seems like the default for dealing with properties is to set the property without and ivar in the implementation file explicitly until you synthesize it with something like: @synthesize var = _var; What's the best practice to use in setting the variable? I know the difference between var and self.var is that self.var is using dot notation and is using the var's setter method. Is _var just the equivalent of setting it

__weak and autorelease pool in ARC in Xcode 4.2

送分小仙女□ 提交于 2019-12-10 10:08:31
问题 My project use ARC. I tested with the code below: NSString __weak *string; @autoreleasepool { string = [NSString stringWithString:@"AAA"]; } NSLog(@"string: %@", string); I think it output as: string: (null) but it actually output: string: AAA I don't understand it. What is the effect of __weak? EDIT: And this code below: NSString __weak *string; NSString __strong *str; @autoreleasepool { str = [NSString stringWithFormat:@"%@", @"AAA" ]; string = str; } NSLog(@"string: %@", string); It also

Clarification about weak references and a retain cycles

自作多情 提交于 2019-12-10 09:30:44
问题 I have the following code: AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest: request]; operation.completionBlock = ^{ if([operation hasAcceptableStatusCode]){ } }; ARC doesn't seem to like [operation hasAcceptableStatusCode], and i get the following warning: "Capturing 'operation' strongly in this block is likely to lead to a retain cycle". I'm not very experienced with referencing, any idea whats the way to go here? Thanks, Shai 回答1: Blocks capture (retain)

“Missing [super dealloc]” warning in an ARC project

泄露秘密 提交于 2019-12-10 04:54:36
问题 I've refactored a project to ARC. It looks fine, but there is an object which uses the notification center. I removed the observer in a custom dealloc method. That worked fine in the non ARC project. It also works in ARC, but I get a crazy warning: "Method possibly missing a [super dealloc] call." In an ARC project it is automatically done for me, when the method ends. Even better: I must not call it in ARC projects! This must be an XCode bug, right? Here's my code: - (void)dealloc { [