我正在实现一个图像浏览器,使用UIScrollView。由于内存costranints,我必须实现图像动态加载(我不想使用CATiled层,因为它迫使用户继续等待加载每个瓷砖)。iphone UIImage内存泄漏
我试着用不同的方式轿跑车:
- (UIImageView*) ldPageView{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Top-level pool
NSError *error;
NSData *imData = [NSData dataWithContentsOfURL:ldPageRef options:NSDataReadingUncached error:&error];
UIImage *im = [[UIImage alloc] initWithData:imData];
ldView = [[UIImageView alloc] initWithImage:im] ;
[ldView setFrame:pageRect];
[pool release]; // Release the objects in the pool.
return ldView;
}
而即使在这样
- (UIImageView*) ldPageView{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Top-level pool
CGDataProviderRef provider = CGDataProviderCreateWithURL ((CFURLRef)ldPageRef);
CGImageRef d = CGImageCreateWithJPEGDataProvider(provider,nil, true,kCGRenderingIntentDefault);
UIImage *im = [[UIImage alloc] initWithCGImage:d];
ldView = [[[UIImageView alloc] initWithImage:im] autorelease];
[im release];
CGDataProviderRelease(provider);
CGImageRelease(d);
[ldView setFrame:pageRect];
[pool release]; // Release the objects in the pool.
return ldView;
}
但每一次我尝试它无论在模拟器和iPad上,内存爆炸。我用仪器运行了我的代码,并且没有泄漏报告。 ldView是一个istance变量,通过ldPageRef对象dealloc(肯定会调用它)释放它。
我也尝试将NSURLCache sharedCache设置为零或为零,但它仍然在发生。
我读过内存管理指南,但everythimg对我来说似乎没问题。 请帮很可能
尝试[pool drain] – Vjy 2010-12-03 18:44:17