[英]Are my properties leaking memory?
- (void)viewDidLoad //In this scenario it only gets called once, but in other bits of code with same property initialisation it might be called more than once
{
deleteButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(deleteModelTapped:)]; //Is this leaking?
self.deleteButton.image = [UIImage imageNamed:[Configuration getDeleteIconName]];
}
@property (nonatomic, retain) IBOutlet UIBarButtonItem *deleteButton;
- (void)dealloc
{
[deleteButton release];
[super dealloc];
}
不,但寫這樣可能更好
- (void)viewDidLoad
{
self.deleteButton = [[[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(deleteModelTapped:)] autorelease];
self.deleteButton.image = [UIImage imageNamed:[Configuration getDeleteIconName]];
}
setProperty展開可能是這樣的
- (void)setProperty:(XXX*)p
{
if ( property != p )
{
[property release];
property = [p retain];
}
}
“泄漏”可能使用“[UIImage imageNamed:]”; :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.