开发者

Intermittent EXC_BAD_ACCESS

开发者 https://www.devze.com 2023-02-17 15:50 出处:网络
I have the following code that creates a modal navigation controller and presents it. DetailViewController *content = [[DetailViewController alloc]initWithNibName:@\"DetailView\" bundle:nil];

I have the following code that creates a modal navigation controller and presents it.

DetailViewController *content = [[DetailViewController alloc]initWithNibName:@"DetailView" bundle:nil];

content.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Close" 
                                                                             style:UIBarButtonItemStylePlain
                                                                            target:content
                                                                            action:@selector(closeButtonPress:)] autorelease]; 
UIN开发者_如何转开发avigationController *modalNavController = [[UINavigationController alloc] initWithRootViewController:content];  
modalNavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentModalViewController:modalNavController animated:YES];

[modalNavController release];

This works fine 99% of the time but on the odd occasion I get a crash..

-[__NSCFType closeButtonPress:]: unrecognized selector sent to instance 0x5ca91d0


The code looks (almost) correct at first sight. But you should release content somewhere, but it's unlikely that the ExcBadAccess happens because of this.

So to hunt this down I would suggest to use NSZombies. NSZombies prevents that your objects get deallocated, they are just marked as deallocated (i.e. turned into zombies).

  1. Open the Executable group in your xcode (3.x) sidebar
  2. Do a right-click and Get Info on your executable
  3. Open the Arguments tab
  4. Add a environment variable under Variables to be set in the environment
  5. Name it NSZombieEnabled and set its value to YES. Make sure that it is activated
  6. Run your code with breakpoints enabled until the zombie object is called

When you know where it happens you can better investigate why it happens.

0

精彩评论

暂无评论...
验证码 换一张
取 消