隨着儀器我得到了這段代碼的內存泄漏,我不明白爲什麼!內存泄漏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