views:

227

answers:

1

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  A: 

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.

Alex
Is there really nothing wrong in that way? I'm a novice at Objective-C, so I'm not sure of this, but when he issues [self.emptyMsg release], doesn't the dot syntax call the setter method such that retain count increases by one? The effect of that statement would then be increasing the retain count by one and decreasing it on one line, wouldn't it?
ustun
No. This would be equivalent to writing [[self emptyMsg] release]. This would call the getter, not the setter.
Alex
Ah, OK, thanks.
ustun