2

我有一个启用弧的项目,它具有 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

photo getter 使用 gcd 调用:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{

    UIImage *cellImage = model.photo;

});

在线的

_photo = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.photoUrl]]];

Instruments 显示 100% 内存泄漏。据我所知,arc 不适用于除主线程之外的线程。那么有没有办法解决这个问题呢?

4

0 回答 0