- (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];
}
问问题
59 次
1 回答
2
不,但这样写可能更好
- (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:]”;:)
于 2012-04-18T15:40:41.843 回答