gcd块中100%内存泄漏

时间:2013-03-31 20:52:43

标签: xcode cocoa memory-leaks instruments grand-central-dispatch

我有一个支持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 getter
dispatch_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不能在线程上工作。那么有什么方法可以解决这个问题吗?

0 个答案:

没有答案