我有一个支持arc的项目,它有PersonModel类:
// .h
@interface PersonModel : NSObject
@property (strong, nonatomic) NSString *photoUrl;
@property (strong, nonatomic) UIImage *photo;
@property (strong, nonatomic) NSString *fio;
@end
// .m
@implementation PersonModel
@synthesize photoUrl;
@synthesize photo = _photo;
@synthesize fio;
- (UIImage *)photo
{
if (_photo == nil && self.photoUrl) {
_photo = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.photoUrl]]];
}
return _photo;
}
@end
使用gcd:
调用photo getterdispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
UIImage *cellImage = model.photo;
});
在线
_photo = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.photoUrl]]];
仪器显示100%内存泄漏。据我所知,除主线程外,arc不能在线程上工作。那么有什么方法可以解决这个问题吗?