我在Xcode上运行了分析版本,并由于对象是属性和实例变量而收到泄漏警告

。H

UIView *_transparentView; }
    @property (nonatomic, retain) UIView *transparentView;


.m

@synthesize transparentView = _transparentView;


self.transparentView = [[UIView alloc] initWithFrame:transparentViewFrame];

- (void)dealloc {
[_transparentView release];


所以我在dealloc上释放了ivar,但是如何释放该属性呢?[self.transparentview release]?

最佳答案

汤姆回答后,将分配“ transparentView”的行替换为:

self.transparentView = [[[UIView alloc] initWithFrame:transparentViewFrame] autorelease];


如果对保留的属性有任何值,则应在完成分配后释放分配的值,并在取消分配类时释放该属性。

07-28 02:06
查看更多