Reputation: 829
Hi I'm dealing with a memory leak but I cannot figure out what problem it is (I don't have either much experience with instruments so please excuse me if I'm asking something obvious).
Basically I have two strings as properties in my class, the very first that will be shown to the user is retrieved in the main queue, and the one that is not required immediately is retrieved in a background queue:
@property (nonatomic, strong) NSString *stringDefaultLocationAddress;
@property (nonatomic, strong) NSString *stringCurrentLocationAddress;
-(void)viewDidLoad{
...
dispatch_async(idQueue, ^(void) {
[self recuperaDireccionActualEnBackground:currentUserLocation.coordinate];
});
}
- (void)dealloc{
[self removeObserver:self forKeyPath:@"playerProfileNeedsUpdate"];
self.stringCurrentLocationAddress = nil;
self.stringDefaultLocationAddress = nil;
}
But I'm getting this leak in instruments:
The problem has to do with the placeholders @" %@..." in stringWithFormat, because if I just put @"Test" at that point the leak is gone, but I don't know why is leaking this and I would like to understand it.
Thanks in advance.
Upvotes: 4
Views: 2392
Reputation: 90571
Instruments tells you the location where a leaked object was allocated, but that may not be the place where it leaked. You need to look at the object's history of retains and releases (click the right-pointing arrow in the circle next to its address). You have to manually analyze each, correlating each retain with the logically corresponding release until you find an unbalanced retain.
If you're using ARC throughout your code, I suspect you've misused __bridge_retained
or CFBridgingRetain()
. Or perhaps you've done a proper bridge cast to a CFStringRef
but then have failed to properly do manual reference counting after that.
Definitely build with the static analyzer and work to eliminate all of the issues it raises (or at least confirm to yourself that they're false positives).
Upvotes: 3