0

我有一个注册方法,它点击一个 API 来注册用户并返回帐户信息。一切正常,但是在我的注册视图控制器中,当注册成功时,我会弹出注册视图。弹出注册视图后,我会在下面的行中获得 EXC_BAD_ACCESS。注意——这只发生在手机上。在模拟器中,这不会发生。不知何故,这似乎是一个时间问题,但我无法弄清楚。例如,如果我在 [_completionHandlerSignUp release] 上放置断点;然后它每次都有效。

这是我的 DataAccessor 类中的 createAccount 方法:

_completionHandlerSignUp = [handler copy];

the normal request code would be here

[request setCompletionBlock:^
 {
     int statusCode = request.responseStatusCode;

     NSDictionary *json = [request.responseString JSONValue];
     NSString *status = [json valueForKeyPath:@"status"];
     NSLog(@"API JSON %@", request.responseString);

     myAccount.statusCode = statusCode;

     if(statusCode == 200)
     {
         myAccount.status = status;
         myAccount.error = @"";
         myAccount.firstName = firstName;
         myAccount.lastName = lastName;
         Credentials *myCredentials = [[Credentials alloc] init];
         myCredentials.emailAddress = userName;
         myCredentials.passWord = passWord;
         myAccount.credentials = myCredentials;

         [myCredentials release];
     }
     else if(statusCode == 403)
     {
         NSString *error = [json valueForKeyPath:@"error"];
         myAccount.status = status;
         myAccount.error = error;
         NSLog(@"API Error %@",error);
     }

     NSLog(@"TEST - Sending Account Response ");
     _completionHandlerSignUp(myAccount);

     NSLog(@"TEST - DEALLOCATING OBJECTS ");

    [_completionHandlerSignUp release];  <--**EXC_BAD_ACCESS HAPPENS HERE**
    _completionHandlerSignUp = nil;

     }];

这是视图控制器方法:

DataAccessor *dataAccessor = [[DataAccessor alloc] init];

        [dataAccessor createAccount:[Utilities getDeviceUDID] user:txtEmail.text password:txtPassword.text firstname:txtFirstName.text lastname:txtLastName.text  completion:^(Account *myAccount)
        {
            [dataAccessor release]; 

            if(myAccount != NULL)
            {
                NSLog(@"Status: %@", myAccount.status);
                NSLog(@"Error: %@", myAccount.error);

                if(myAccount.statusCode == 200)  //handle successful transaction
                {

                    [Preferences signInUser:myAccount.credentials.emailAddress password:myAccount.credentials.passWord];

                    [self popViewController];  **<<<<If I remove this, THERE IS NO CRASH******
                }
                else if(myAccount.statusCode == 403)
                {
                    //todo - handle error
                }
            }


            [self finalUpdate];
        }];

- (void) popViewController
{
    NSLog(@"TEST - Popping View Controller ");

    CATransition* transition = [CATransition animation];
    transition.duration = 0.5;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
    transition.subtype = kCATransitionFromBottom; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
    //  MainSelectionMenu *myViewController = [[MainSelectionMenu alloc] initWithNibName:@"MainSelectionMenu" bundle:nil];
    [self.navigationController.view.layer addAnimation:transition forKey:nil];
    [[self navigationController] popViewControllerAnimated:NO];
}

另一个非常奇怪的事情是我的登录功能几乎完全相同。登录调用 DataAccessor 中的 SignIN API,当它在视图控制器中返回时,它会弹出视图。但是,登录功能可以正常工作并且永远不会崩溃。

编辑 - 僵尸日志:

- 地址类别 事件类型 RefCt 时间戳大小 责任库 责任调用者
0 0x11035a00 ASIFormDataRequest Malloc 1 00:16.125.952 1024 Saveology +[ASIFormDataRequest requestWithURL:]
1 0x11035a00 ASIFormDataRequest 自动释放 00:16.126.025 0 Saveology +[ASIFormDataRequest requestWithURL:]
2 0x11035a00 ASIFormDataRequest Autorelease 00:16.126.026 0 Saveology-[SaveologyDealsDataAccessor createDealsAccount:user:password:firstname:lastname:divisionid:completion:]
3 0x11035a00 ASIFormDataRequest 保留 2 00:16.126.179 0 基金会 NSRecordAllocationEvent
4 0x11035a00 ASIFormDataRequest 保留 3 00:16.126.196 0 基金会 NSRecordAllocationEvent
5 0x11035a00 ASIFormDataRequest 发布 2 00:16.126.266 0 基金会 NSRecordAllocationEvent
6 0x11035a00 ASIFormDataRequest 发布 1 00:16.126.267 0 基金会 NSRecordAllocationEvent
7 0x11035a00 ASIFormDataRequest 保留 2 00:16.127.268 0 基金会 NSRecordAllocationEvent
8 0x11035a00 ASIFormDataRequest 保留 3 00:16.127.302 0 基金会 NSRecordAllocationEvent
9 0x11035a00 ASIFormDataRequest 版本 2 00:16.127.332 0 基金会 NSRecordAllocationEvent
10 0x11035a00 ASIFormDataRequest 保留 3 00:16.128.711 0 基金会 NSRecordAllocationEvent
11 0x11035a00 ASIFormDataRequest 发布 2 00:16.128.771 0 基金会 NSRecordAllocationEvent
12 0x11035a00 ASIFormDataRequest 保留 3 00:16.129.880 0 基金会 NSRecordAllocationEvent
13 0x11035a00 ASIFormDataRequest 保留 4 00:16.129.889 0 基金会 NSRecordAllocationEvent
14 0x11035a00 ASIFormDataRequest 发布 3 00:16.129.893 0 基金会 NSRecordAllocationEvent
15 0x11035a00 ASIFormDataRequest 发布 2 00:16.129.912 0 基金会 NSRecordAllocationEvent
16 0x11035a00 ASIFormDataRequest 保留 3 00:16.309.250 0 基金会 NSRecordAllocationEvent
17 0x11035a00 ASIFormDataRequest 保留 4 00:16.310.289 0 基金会 NSRecordAllocationEvent
18 0x11035a00 ASIFormDataRequest 发布 3 00:16.310.396 0 基金会 NSRecordAllocationEvent
19 0x11035a00 ASIFormDataRequest 发布 2 00:16.310.640 0 基金会 NSRecordAllocationEvent
20 0x11035a00 ASIFormDataRequest 保留 3 00:16.310.775 0 基金会 NSRecordAllocationEvent
21 0x11035a00 ASIFormDataRequest 保留 4 00:16.310.776 0 基金会 NSRecordAllocationEvent
22 0x11035a00 ASIFormDataRequest 发布 3 00:16.310.789 0 基金会 NSRecordAllocationEvent
23 0x11035a00 ASIFormDataRequest 发布 2 00:16.310.807 0 基金会 NSRecordAllocationEvent
24 0x11035a00 ASIFormDataRequest 保留 3 00:16.311.443 0 基金会 NSRecordAllocationEvent
25 0x11035a00 ASIFormDataRequest 保留 4 00:16.311.469 0 基金会 NSRecordAllocationEvent
26 0x11035a00 ASIFormDataRequest 保留 5 00:16.311.491 0 基金会 NSRecordAllocationEvent
27 0x11035a00 ASIFormDataRequest 保留 6 00:16.311.496 0 基金会 NSRecordAllocationEvent
28 0x11035a00 ASIFormDataRequest 发布 5 00:16.311.501 0 基金会 NSRecordAllocationEvent
29 0x11035a00 ASIFormDataRequest 发布 4 00:16.311.546 0 基金会 NSRecordAllocationEvent
30 0x11035a00 ASIFormDataRequest 发布 3 00:16.311.557 0 基金会 NSRecordAllocationEvent
31 0x11035a00 ASIFormDataRequest 发布 2 00:16.311.563 0 基金会 NSRecordAllocationEvent
32 0x11035a00 ASIFormDataRequest 发布 1 00:16.313.736 0 基金会 NSRecordAllocationEvent
33 0x11035a00 ASIFormDataRequest 发布 0 00:16.320.573 0 基金会 NSRecordAllocationEvent
34 0x11035a00 ASIFormDataRequest 僵尸 -1 00:16.320.964 0 图形服务 GSEventRunModal
4

1 回答 1

0

打开 Zombie Objects 以获取有关 EXE_BAD_ACCESS 错误的更多详细信息。应该告诉你一些关于它期望在那里的对象的信息。这通常意味着您在执行代码时过早地释放了对象指针。

打开僵尸:如何在 Xcode 4 中设置 NSZombieEnabled?

当您删除此 [_completionHandlerSignUp release] 行时会发生什么?

于 2012-01-27T19:47:59.290 回答