1
votes

I think it could cause an error because, I have used layer property of button in several classes. I think this could be the reason but I am not sure.

Now, when I am running my application on iPod after sometime (5 minutes max) the application crashes with the following error message:

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

How do I solve this problem?

3
Post some more code.. How did you allocate the CALayer instance? - Ilanchezhian

3 Answers

0
votes

You're getting the error because an object has been deallocated and you are trying to send it a message.

Without seeing your code, it is difficult to say what you need to do in order to fix the problem.

I would suggest you read up on memory management in objective-c. For example,

Apple Documentation for Memory Management

But there are many other documents about it. If you don't understand these concepts, then you are going to have many problems in the future.

0
votes

If you wanna remove the class self in the current view, and it had have IBOutlets connect with the removed view that you did need to setup the IBOutlets to nil, it still works for me, like this :

-(void)backRootController{
    //I wanna change the current viewController to rootViewController on self.tabBarController.
    RootViewController *_rootViewController = [[RootViewController alloc] init];
    NSArray *_viewControllers = self.tabBarController.viewControllers;
    NSMutableArray *_tabs     = [NSMutableArray array];
    for( UIViewController *_tabViewController in _viewControllers ){
        if( _tabViewController == self ){
            _rootViewController.tabBarItem = _tabViewController.tabBarItem;
            _tabViewController = _rootViewController;
        }
        [_tabs addObject:_tabViewController];
    }
    self.tabBarController.viewControllers = [NSArray arrayWithArray:_tabs];

    //To setup the IBOutlets to nil to avoid [CALayer release] crash. ( UILabel, UIView, UIImageView )
    self.outPreviewLabel           = nil;
    self.outPreviewView            = nil;
    self.outPreviewImageView.image = nil;
    self.outPreviewImageView       = nil;

    //Then remove the view and exchanged current controller.
    [self.view removeFromSuperview];
    [self removeFromParentViewController];
    [_rootViewController release];
}
-4
votes

I think you haven't retained your buttons in your viewDidLoad method, thats why after some time they deallocate. Just add retain at the end where you alloc it or write it in @property..