【发布时间】:2018-05-27 12:21:15
【问题描述】:
我使用在该操作中声明的对象声明了 NSBlockOperation。由于内存问题,我的应用程序经常崩溃。感谢任何提示并对此进行了很好的解释,花了几个小时仍然没有成功。
运行时:内存问题 -(5 种泄露类型):NSExactBlockVariable 的 1 个实例泄露
- (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;
}
【问题讨论】:
-
显示
EMUserInfoOperation的实现(至少是它的初始化程序、dealloc 和任何超类方法的覆盖)以及使用从这个-loadingLocalModelOperationWithColor:gender:方法返回的对象的代码。没有这些信息,我们无法猜测发生了什么。此外,使用 Leaks 工具模板运行应用程序并显示泄漏对象的保留/释放历史记录。
标签: objective-c xcode memory retain-cycle nsblockoperation