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