1
我有一个泄漏,下面的代码建立!为什么我有这个问题?是由于它复制了NSString中的属性。有没有解决的办法?设置MKAnnotation标题和子标题时泄漏
@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];
}
该方法中每个属性设置的泄漏都是50%。
UPDATE
原来这是正在从最终的块调用。为了尝试解决这个问题,我做了以下工作。
下面的工作,但仍然泄漏,现在明确自我保留。
-(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];
});
}
但是,泄漏和以下应该在理论上的工作给setTitle方法一个无法识别的选择器!!!!!你不使用ARC
-(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];
});
}
你重写标题和副标题制定者? – jbat100 2011-12-14 10:44:44
它们未被覆盖 – 2011-12-14 10:45:48