开发者

Whats the correct way to release a @property / IBOulet for UIViewController

I've read many different things about correct memory management for cocoa/objective-c

For instance ive read that any IBOutlets need to be set to 'nil' but something like an NSArray dosnt?

I would also like to know, is it important to call the super method before or after i release/nil everything

To put this memory issue to bed, can some please reply with the 100% correct way you would create a retained property and relea开发者_运维问答se it. If your not 100% sure please dont answer.

Here is what im currently doing but something is obviously wrong as i get the very frustrating EXEC_BAD_ACCESS!?! Almost like im releasing something twice?

header.h

@interface MyViewController : UIViewController {

    UILabel *aLabel;
    NSArray *aArray;

}
@property (nonatomic, retain) IBOutlet UILabel *aLabel;
@property (nonatomic, retain) NSArray *aArray;

method.m

@implementation MyViewController

@synthesize aLabel, aArray;

- (void)dealloc
{
     [aLabel release], aLabel = nil;
     [aArray release];
     [super dealloc];
}

- (void)viewDidUnload
{
    self.aLabel = nil; //Not sure about this bad boy???
    [super viewDidUnload];
}

@end


In dealloc you have released the aLabel.Means it is not in memory.Again you are write this line ---aLabel=nil;Remove this line.So that it can't gives the Exec_badaccess.This means eventhough you don't have pointer stilll you are trying to access the pointer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜