Search code examples
iphoneobjective-creleaseandroid-mapviewcalayer

"[CALayer release]: message sent to deallocated instance" in UIViewController


I have a MapView in an UIViewController. When I try to load the view after its viewDidUnload it crashes with this message:

-[CALayer release]: message sent to deallocated instance 0x29aea0

I think I do all the necessary things that I should do i the viewDidUnload:

- (void)viewDidUnload {

    [super viewDidUnload];

    locationManager.delegate = nil;
    [locationManager release];
    locationManager = nil;

    mapView.delegate = nil;
    [mapView release];
    mapView = nil;
}

My MapView is in an UIView configured in a xib-file. My VC is never deallocated.

I have been googling around for a while now but I can't find the answer.

Edit

 - (void)viewDidLoad {

    [super viewDidLoad];

    locationManager = [[CLLocationManager alloc] init];
    [locationManager setDelegate:self];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [locationManager startUpdatingLocation];

    [label setFont:[UIFont fontWithName:@"Sansation" size:28]];
    [label setShadowOffset:CGSizeMake(0, 1)];
    [label setShadowColor:[UIColor grayColor]];
    self.navigationItem.titleView = labelView;
    [label release];
    [labelView release];

    UIBarButtonItem *checkInButton = [[UIBarButtonItem alloc] initWithTitle:@"Checka In" style:UIBarButtonItemStylePlain target:self action:@selector(checkIn)];
    [[self navigationItem] setRightBarButtonItem:checkInButton];
    [checkInButton release];

    UIBarButtonItem *clueListButton = [[UIBarButtonItem alloc] initWithTitle:@"Ledtrådar" style:UIBarButtonItemStylePlain target:self action:@selector(cluesDown)];
    [[self navigationItem] setLeftBarButtonItem:clueListButton];
    [clueListButton release];

    UINavigationBar *bar = [self.navigationController navigationBar]; 
    [bar setTintColor:[UIColor colorWithRed:0.06 green:0.58 blue:0.88 alpha:1]]; 
}

"labelView" and "label" are IBOutlets.


Solution

  • Since you have neither allocated nor retained label and labelView in your viewDidLoad method you may not release them here (you are overreleasing them).