Crash on master/detail app, when changing category, after releasing Var
I'm struggling to figure out why my app is crashing when I release synthesi开发者_C百科zed properties. My app launches, and when I tap on a row, it takes me to DetailViewController, then when I go back and tap a row again the app crashes with EXC_BAD_ACCESS.
DetailViewController.h:
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController {
IBOutlet UILabel *clipboardLabel;
}
@property (nonatomic, retain) IBOutlet UILabel *clipboardLabel;
@end
DetailViewController.m
#import "DetailViewController.h"
@implementation DetailViewController
@synthesize clipboardLabel;
- (void)viewDidLoad
{
// Do any additional setup after loading the view from its nib.
clipboardLabel.text = @"Tap an image to copy";
[super viewDidLoad];
}
- (void)dealloc
{
[clipboardLabel dealloc];
[super dealloc];
}
@end
Call release
instead of dealloc
on your clipboardLabel in the dealloc
method.
That should be :
- (void)dealloc
{
[clipboardLabel release];
[super dealloc];
}
A general rule : one should never call dealloc
on another object.
Do not call dealloc
:
[clipboardLabel dealloc]; <-- Wrong
call release:
[clipboardLabel release]; <-- Right
精彩评论