Search code examples
iosmemory-managementios4

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 synthesized 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

Solution

  • 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 deallocon another object.