can't do super dealloc and need explanation about dealloc and release what is the differences between them?

StackOverflow https://stackoverflow.com/questions/18110152

  •  23-06-2022
  •  | 
  •  

Question

That code is right? It doesn't dealloc and release it's saying that "super dealloc ARC forbids" when I need to do dealloc and when I need to do release?

#import "ImageViewController.h"

@interface ImageViewController ()
@end
@implementation ImageViewController
@synthesize imageToDisplay=_imageToDisplay;

-(IBAction)click:(id)sender
{
    if ([[sender title]isEqualToString:@"Dog"])
    {
        [_imageToDisplay setImage:[UIImage imageNamed:@"border-collie_177061-1280x1024.jpg"]];
    }
    else if ([[sender title]isEqualToString:@"FakeBook"])
    {
        [_imageToDisplay setImage:[UIImage imageNamed:@"images.jpeg"]];
    }//else if
}//click


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)dealloc
{
    [_imageToDisplay release];
    [super dealloc];
}


@end
Was it helpful?

Solution

[super dealloc] and release are not permitted when using ARC. The goal of ARC is to manage this automatically so you don't need to worry about it. If you prefer to release your objects manually, then switching off ARC is the way to go.

OTHER TIPS

You cannot dealloc or release something if you are using arc. You can set _imageToDisplay to nil in dealloc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top