仪器显示假漏? [英] Instruments showing false leak?
问题描述
我不知道为什么仪器显示以下代码泄漏128字节在UILabel initWithFrame行:
self。 navigationItem.leftBarButtonItem = self.editButtonItem;
UILabel * tmp = [[UILabel alloc] initWithFrame:CGRectMake(25,100,275,100)];
self.emptyMsg = tmp;
[tmp release];请注意,在这个类中释放下面的emptyMsg属性:
b
- (void)dealloc {
[self.emptyMsg release]
[self.pathToUsersFriendsFile release];
[super dealloc];
}
有一点我没有使用访问器方法来设置emptyMsg,所以我期望改变使这种泄漏消失。唉,它仍然出现。
变量声明:
@interface FriendListViewController:UITableViewController< AddFriendDelegate> {
NSString * pathToUsersFriendsFile;
UILabel * blankMsg;
}
@property(retain)UILabel * emptyMsg;
@end
解决方案方式你做到了。 (虽然我会采取Rich的意见,并且不使用 dealloc
方法中的点语法;然后释放实例变量。)仪器不应该困惑它,但仪器不是完美的。如果坚持这是一个内存泄漏,这是一个假阳性。
I am not sure why Instruments is showing the following code as leaking 128 bytes on the UILabel initWithFrame line:
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UILabel *tmp = [[UILabel alloc] initWithFrame:CGRectMake(25, 100, 275, 100)];
self.emptyMsg = tmp;
[tmp release];
Note that in this classes is releasing the emptyMsg property in the following:
-(void) dealloc {
[self.emptyMsg release];
[self.pathToUsersFriendsFile release];
[super dealloc];
}
At one point I wasn't using the accessor method to set emptyMsg so I expected that change to the make this leak go away. Alas, it is still showing up. Can some one point me to another cause?
Declaration of variable:
@interface FriendListViewController : UITableViewController <AddFriendDelegate> {
NSString *pathToUsersFriendsFile;
UILabel *emptyMsg;
}
@property(retain) UILabel *emptyMsg;
@end
解决方案 There's nothing wrong with the way you've done it. (Although I would take Rich's advice and not use the dot syntax in the dealloc
method; release the instance variables instead.) Instruments shouldn't be confused by it, but Instruments is not perfect. If it is insisting that's a memory leak, it's a false positive.
这篇关于仪器显示假漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!