I should be doing something wrong, but the Automatic Reference Counting docs don't give me clues about what this might be. What I'm doing is a method call with a block callback from the delegate method. Access to the same delegate from within the block results in poor access . The problem is that the object I'm passing in - loginController , which sends a message to its delegate - is obviously not released, when I cannot access it inside the block, I can call this method several times without a question. Here is my code:
- (void)loginViewDidSubmit:(MyLoginViewController *)loginController { NSString *user = loginController.usernameLabel.text; NSString *pass = loginController.passwordLabel.text; __block MyLoginViewController *theController = loginController; [self loginUser:user withPassword:pass callback:^(NSString *errorMessage) { DLog(@"error: %@", errorMessage); DLog(@"View Controller: %@", theController);
NSZombieEnabled does not register anything and there is no useful stack trace from gdb. What am I doing wrong here? Thanks for any pointers!
Edit:
I realized that the problem is larger - the callback above is called from the NSURLConnectionDelegate method (the block itself is a strong property for this delegate, so ARC should call Block_copy ()). Do I need to take special measurements in this scenario?
Flow (loginController remains visible all the time):
LoginController
[delegate loginViewDidSubmit:self]
View Delegate
(method shown above calls the loginUser: method, which does something like:) httpDelegate.currentCallback = callback; httpDelegate.currentConnection = // linebreak for readability [[NSURLConnection alloc] initWithRequest:req delegate:httpDelegate startImmediately:YES];
NSURLConnectionDelegate
- (void)connection:(NSURLConnection *)aConnection didFailWithError:(NSError *)error { if (NULL != currentCallback) { currentCallback([error localizedDescription]); self.currentCallback = NULL; } }
And here I get bad access, but ONLY if I get access to this loginController variable ...
source share