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

문제

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
도움이 되었습니까?

해결책

[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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top