NSString stringwithFormat memory leak using ARC

Hi, I am dealing with a memory leak, but I can’t understand what the problem is (I don’t have much experience with tools, so please excuse me if I ask for something obvious).

Basically, I have two lines as properties in my class, the first one that will be shown to the user will be retrieved in the main queue, and the one that is not required immediately will be restored in the background:

@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 get this leak in tools: code leak enter image description here

The problem is with @ "% @ ..." placeholders in stringWithFormat, because if I just put @ "Test" at that moment, the leak will disappear, but I don’t know why it is leaking this and I would like to understand it.

Thanks in advance.

+4
source share
1 answer

The tools tell you the location where the leaked object was highlighted, but this may not be the place where it leaked. You need to look at the history of the save and release objects (click the arrow with the right arrow in the circle next to its address). You must manually analyze each one, matching each one with a logically relevant release, until you find an unbalanced save.

If you use ARC in all of your code, I suspect that you used __bridge_retained or CFBridgingRetain() incorrectly. Or, you may have done the correct bridge transfer to CFStringRef , but after that you couldn’t perform manual reference counting after that.

Definitely build with a static analyzer and work to eliminate all the problems that it raises (or at least confirm to yourself that they are false positives).

+3
source

Source: https://habr.com/ru/post/1483001/


All Articles