将视图推送到导航堆栈后释放给我 exc_bad_access 错误

发布于 2024-10-04 16:17:31 字数 2997 浏览 0 评论 0原文

以下代码位于 tableView didSelectRowAtIndexPath 中,如果版本未注释,我会收到错误:

ComicDetailsViewController * comicDetailsViewController = [[ComicDetailsViewController alloc] initWithNibName:@"ComicDetailsViewController" bundle:nil];
       comicDetailsViewController.comic = (Comic *)[arrayOfComics objectAtIndex:indexPath.row];
       comicDetailsViewController.bLoadPerformances = YES;
       [self.navigationController pushViewController:comicDetailsViewController animated:YES];
       //[comicDetailsViewController release];

错误不会立即发生,而是在我单击 omicDetailsViewController 中的后退按钮后发生。

即。)我选择表视图行,下一个视图将加载并正常工作。一旦我完成该视图并单击后退导航按钮,程序就会崩溃并给我 exc_bad_access 。这是为什么呢?

编辑:

#0  0x9682b176 in __kill
#1  0x9682b168 in kill$UNIX2003
#2  0x968bd89d in raise
#3  0x968d39bc in abort
#4  0x968c2164 in szone_error
#5  0x968c21e7 in free_small_botch
#6  0x000a7877 in -[NSConcreteMutableData dealloc]
#7  0x00006433 in -[ComicDetailsViewController dealloc] at ComicDetailsViewController.m:376
#8  0x003cbcc7 in -[UINavigationController setDisappearingViewController:]
#9  0x003c9219 in -[UINavigationController _clearLastOperation]
#10 0x003c9b62 in -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
#11 0x0055224a in -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:]
#12 0x0055338a in -[UINavigationTransitionView _navigationTransitionDidStop]
#13 0x0034829d in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
#14 0x0034812f in -[UIViewAnimationState animationDidStop:finished:]
#15 0x0244ca28 in run_animation_callbacks
#16 0x0244c8e9 in CA::timer_callback
#17 0x02688d43 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
#18 0x0268a384 in __CFRunLoopDoTimer
#19 0x025e6d09 in __CFRunLoopRun
#20 0x025e6280 in CFRunLoopRunSpecific
#21 0x025e61a1 in CFRunLoopRunInMode
#22 0x02f0c2c8 in GSEventRunModal
#23 0x02f0c38d in GSEventRun
#24 0x00326b58 in UIApplicationMain
#25 0x000020f4 in main at main.m:14

编辑2:

这是comicDetailsViewController dealloc块:

- (void)dealloc {
[comic release];
[xmlParser release];
[webData release];
[currentPerformanceObject release];
[arrayOfPerformances release];
[soapResults release];
[btnPerformances release];
[super dealloc];

}

第376行是webData发布行

编辑3:

    -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    NSLog(@"ERROR with theConenction");
    [connection release];
    [webData release];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"DONE. Received Bytes: %d", [webData length]);

    if(xmlParser)
    {
        [xmlParser release];
    }

    xmlParser = [[NSXMLParser alloc] initWithData: webData];
    [xmlParser setDelegate: self];
    [xmlParser setShouldResolveExternalEntities: YES];
    [xmlParser parse];

    [connection release];
    [webData release];
}

The following code is in the tableView didSelectRowAtIndexPath if the release is uncommented i get the error:

ComicDetailsViewController * comicDetailsViewController = [[ComicDetailsViewController alloc] initWithNibName:@"ComicDetailsViewController" bundle:nil];
       comicDetailsViewController.comic = (Comic *)[arrayOfComics objectAtIndex:indexPath.row];
       comicDetailsViewController.bLoadPerformances = YES;
       [self.navigationController pushViewController:comicDetailsViewController animated:YES];
       //[comicDetailsViewController release];

The error does not happen right away, it happens once i click the back button in the omicDetailsViewController.

ie.) i select the tableview row, the next view loads and works properly. Once i am done with that view and click the back navigation button the program crashes and gives me exc_bad_access. Why is this?

EDIT:

#0  0x9682b176 in __kill
#1  0x9682b168 in kill$UNIX2003
#2  0x968bd89d in raise
#3  0x968d39bc in abort
#4  0x968c2164 in szone_error
#5  0x968c21e7 in free_small_botch
#6  0x000a7877 in -[NSConcreteMutableData dealloc]
#7  0x00006433 in -[ComicDetailsViewController dealloc] at ComicDetailsViewController.m:376
#8  0x003cbcc7 in -[UINavigationController setDisappearingViewController:]
#9  0x003c9219 in -[UINavigationController _clearLastOperation]
#10 0x003c9b62 in -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
#11 0x0055224a in -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:]
#12 0x0055338a in -[UINavigationTransitionView _navigationTransitionDidStop]
#13 0x0034829d in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
#14 0x0034812f in -[UIViewAnimationState animationDidStop:finished:]
#15 0x0244ca28 in run_animation_callbacks
#16 0x0244c8e9 in CA::timer_callback
#17 0x02688d43 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
#18 0x0268a384 in __CFRunLoopDoTimer
#19 0x025e6d09 in __CFRunLoopRun
#20 0x025e6280 in CFRunLoopRunSpecific
#21 0x025e61a1 in CFRunLoopRunInMode
#22 0x02f0c2c8 in GSEventRunModal
#23 0x02f0c38d in GSEventRun
#24 0x00326b58 in UIApplicationMain
#25 0x000020f4 in main at main.m:14

Edit 2:

Here is the comicDetailsViewController dealloc block:

- (void)dealloc {
[comic release];
[xmlParser release];
[webData release];
[currentPerformanceObject release];
[arrayOfPerformances release];
[soapResults release];
[btnPerformances release];
[super dealloc];

}

Line 376 is the webData release line

EDIT 3:

    -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    NSLog(@"ERROR with theConenction");
    [connection release];
    [webData release];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"DONE. Received Bytes: %d", [webData length]);

    if(xmlParser)
    {
        [xmlParser release];
    }

    xmlParser = [[NSXMLParser alloc] initWithData: webData];
    [xmlParser setDelegate: self];
    [xmlParser setShouldResolveExternalEntities: YES];
    [xmlParser parse];

    [connection release];
    [webData release];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

著墨染雨君画夕 2024-10-11 16:17:31

请向我们展示堆栈跟踪。

但我最初的猜测是您在 ComicDetailsViewController 类的 - (void) dealloc 中做错了什么。

请检查一些事情

  • 您的dealloc块是否正常
  • 您没有释放comicDetailsViewController对象或从其他地方对其的引用。

希望这有帮助。

谢谢,
马杜普

Please show us the stack trace.

But my initial guess is you are doing something wrong in - (void) dealloc of your ComicDetailsViewController class.

Please check for few things

  • Your dealloc block is alright
  • You are not releasing comicDetailsViewController object or a reference to it from somewhere else.

Hope this helps.

Thanks,
Madhup

笑饮青盏花 2024-10-11 16:17:31

在弹出视图之前,通过向适当的对象发送取消消息来取消 NSURLConnection。

假设您的 NSURLConnection 对象名为 asyncConnection:

-(void)viewWillDisappear:(BOOL)animated
   [asyncConnection cancel];
}

Before popping the view out, cancel your NSURLConnection by sending a cancel message to the appropriate object.

Assuming your NSURLConnection object is named asyncConnection:

-(void)viewWillDisappear:(BOOL)animated
   [asyncConnection cancel];
}
半暖夏伤 2024-10-11 16:17:31

问题仍然可能出在您的释放中。

仅仅因为该对象位于您的 @interface (.h 文件)中,并不意味着您可以/必须释放该变量。我也遇到这个问题

.h 文件

@interface PeopleViewController : UITableViewController {
NSArray *people;
}

@property (nonatomic, retain) NSArray *people;

@end

.m 文件

@implementation PeopleViewController

@synthesize people;

- (void)viewDidLoad {
    people = [town.people allObjects];
}

...

- (void)dealloc {
    [people release];
}

@end

我不需要释放人员,因为我在 in 时没有增加对象的保留计数我的自定义视图,因此在释放过程中释放它导致了我的问题。

The problem is still possibly in your dealloc.

Just because the object is in your @interface (.h file), that does not mean that you can/have to dealloc the variable. I had this problem as well

.h file

@interface PeopleViewController : UITableViewController {
NSArray *people;
}

@property (nonatomic, retain) NSArray *people;

@end

.m file

@implementation PeopleViewController

@synthesize people;

- (void)viewDidLoad {
    people = [town.people allObjects];
}

...

- (void)dealloc {
    [people release];
}

@end

I didn't need to release people because I didn't increase the retain count on the object while in was in my custom view, therefore releasing it during the dealloc process caused my problems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文