随着仪器我得到了这段代码的内存泄漏,我不明白为什么!内存泄漏NSAutoreleasePool
-(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];
}
由于
你正在为分离的线程做这件事,对吧? – 2011-04-23 11:37:41
是的,这就是为什么我分配一个NSAutoreleasePool到这个方法:) – vince 2011-04-23 12:45:19