Instruments showing false leak?

2019-05-19 14:06发布

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

1条回答
劫难
2楼-- · 2019-05-19 14:19

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.

查看更多
登录 后发表回答