4
嗨我正在处理内存泄漏,但我不知道它是什么问题(我没有太多的仪器经验,所以请原谅,如果我问一些明显的问题) 。NSString stringwithwith内存泄漏与ARC
基本上我有两个字符串作为在我的类属性,第一个将要显示给用户的主队列被检索,并且不立即需要在背景队列中检索到的一个:
在stringWithFormat问题与占位符做@“%@ ...”,因为如果我只是把@‘测试’:
@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;
}
但我得到这个泄漏的仪器那时泄漏消失了,但我不知道为什么泄漏这一点,我想了解它。
在此先感谢。
如果你只是放了'@“Test”''''''''''''''''''''''''''''''消息' - [NSString copy]'当它是可变的('NSMutableString'的子类)时产生一个副本,或者当它是不可变的时候保留('NSString'的子类)。因此,在声明'NSString'时总是复制。复制可变字符串可确保客户端不会远程更改保存在属性中的值。如果您使用的是iOS 5,则“CLGeocoder”中有地理编码和反向地理编码,您不需要库。你不需要在'dealloc'中删除变量,ARC已经释放了这些属性。 – Jano
我感谢你@Jano的回复,我刚刚添加了COPY消息,现在我没有内存泄漏,谢谢你的回应。 – Rubs
我的意思是声明:@property(nonatomic,COPY)NSString * stringDefaultLocationAddress; – Rubs