Xcode 分析器抱怨存储在"assign" @property中的 CFContextRef



我有一个Cocoa类,它需要长时间保留位图上下文来进行像素操作。

@property (assign, nonatomic) CGContextRef cacheContext; // block of pixels

在我的类初始化中:

// this creates a 32bit ARGB context, fills it with the contents of a UIImage and returns a CGContextRef
[self setCacheContext:[self allocContextWithImage:[self someImage]]];

在交易中:

CGContextRelease([self cacheContext]);

Xcode 分析器公司关于 init 泄漏了 CGContextRef 类型的对象,并且在 dealloc 中有一个关于"不正确地减少不属于调用方的对象"的投诉。

我相信这一切都很好,它运行得很好。

我怎样才能告诉 Xcode 这一切都没问题,不要抱怨它?

好的,鉴于这里的讨论,我认为可以解决分析器投诉,让您保留正式属性,并且不违反任何内存管理规则。

声明只读属性:

@property (readonly) CGContextRef cacheContext;

在创建 ivar 时直接分配它

_cacheContext = [self allocContextWithImage:self.someImage];

dealloc发布它:

- (void)dealloc
{
CGContextRelease(_cacheContext);
[super dealloc];
}

相关内容

最新更新