【发布时间】:2011-08-11 11:01:16
【问题描述】:
使用仪器时,我在这段代码上遇到了内存泄漏,我不明白为什么!
-(void)goToThisUrl:(id) targetUrl
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (someCondition) {
// Doing some stuff here
}
// Instruments show memory leak on data
else {
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString: targetUrl]];
myTargetImage = [UIImage imageWithData:data];
// When releasing data(because data retainCount = 2), i got:
// Incorrect decrement of the reference count of an object that is not owned at this point by the caller
//[data release];
}
[pool release];
}
谢谢
【问题讨论】:
-
你这样做是为了一个分离的线程,对吧?
-
是的,这就是为什么我为这个方法分配一个 NSAutoreleasePool :)
标签: memory-leaks uiimage nsdata instruments nsautoreleasepool