Note that there are some explanatory texts on larger screens.

plurals
  1. POLeak when setting MKAnnotation Title and SubTitle
    text
    copied!<p>I have a leak with the following code that builds up! Why do I have this issue? Is it due to it copying the properties inside the NSString. Is there a way around this?</p> <pre><code>@property (nonatomic, copy) NSString *reg; @property (nonatomic, copy) NSString *reg2; @property (nonatomic, copy) NSNumber *altitude; @property (nonatomic, copy) NSNumber *heading; -(void)updateTitles{ self.title=[NSString stringWithFormat:@"%@ %@",self.reg,self.reg2]; self.subtitle = [NSString stringWithFormat:@"%@ft %@°",self.altitude,self.heading]; } </code></pre> <p>The leak is 50% on each of the setting of properties inside this method.</p> <p><strong>UPDATE</strong></p> <p>Turns out this was being called from a block ultimately. To try and work around this I did the following.</p> <p>The following works but still leaks, clear now that self is retained.</p> <pre><code>-(void)updateTitles{ __block NSString *thisTitle = [[NSString alloc] initWithFormat:@"%@ %@",self.reg1,self.reg2]; __block NSString *subTitle = [[NSString alloc] initWithFormat:@"%@ft %@°",self.altitude,self.heading]; dispatch_queue_t mainQueue = dispatch_get_main_queue(); dispatch_async(mainQueue,^(){ self.title=thisTitle; self.subtitle = subTitle; [thisTitle release]; [subTitle release]; }); } </code></pre> <p>However that leaks and the following which should in theory work gives an unrecognised selector on the setTitle method!!!!!</p> <pre><code>-(void)updateTitles{ __block NSString *thisTitle = [[NSString alloc] initWithFormat:@"%@ %@",self.reg1,self.reg2]; __block NSString *subTitle = [[NSString alloc] initWithFormat:@"%@ft %@°",self.altitude,self.heading]; __block __typeof__(self) blockSelf = self; dispatch_queue_t mainQueue = dispatch_get_main_queue(); dispatch_async(mainQueue,^(){ [blockSelf setTitle:thisTitle]; [blockSelf setSubtitle:subTitle]; [thisTitle release]; [subTitle release]; }); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload