我使用在该操作中声明的对象声明了NSBlockOperation。由于内存问题,我的应用程序不断崩溃。感谢任何关于这个问题的很好解释的暗示,花了几个小时还是没有成功。
运行时:内存问题- (5种泄漏类型):NSExactBlockVariable的一个实例泄漏
- (EMUserInfoOperation*)loadingLocalModelOperationWithColor:(EMOutfitColor)outfitColor gender:(EMGender)gender {
__block EMUserInfoOperation* operation = [EMUserInfoOperation blockOperationWithBlock:^{
NSURL* remoteURL = [NSURL URLWithString:self.settings[kEMRemoteUrlKey]];
EMOutfitModel* model = nil;
if (remoteURL == nil) {
model = [[EMDomainDataLoader sharedLoader] loadEmbededOutfitNamed:self.name gender:gender];
} else {
model = [[EMDomainDataLoader sharedLoader] loadCachedOutfitNamed:self.name withVersion:self.version gender:gender];
}
[model syncApplyTextureFromPath:[self texturePathForColor:outfitColor] textureSampler:EMTextureSamplerColor];
NSString *alphaPath = [self texturePathForAlpha];
if(alphaPath.length > 0) {
[model syncApplyTextureFromPath:alphaPath textureSampler:EMTextureSamplerAlpha];
}
operation.userInfo = model;
}];
return operation;
}发布于 2018-05-27 17:46:45
我猜您的EMUserInfoOperation对象对创建操作的块有很强的引用。这个块还具有对EMUserInfoOperation对象的强烈引用,因为它捕获了operation变量。所以你有一个保留周期。
通过执行以下操作,可以使块仅弱引用EMUserInfoOperation对象:
EMUserInfoOperation* operation;
__block __weak typeof(operation) weakOperation;
weakOperation = operation = [EMUserInfoOperation blockOperationWithBlock:^{
typeof(operation) strongOperation = weakOperation;
if (strongOperation) {
// ...
strongOperation.userInfo = model;
}
}];
return operation;https://stackoverflow.com/questions/50552082
复制相似问题