私はUIScrollViewを使用してイメージブラウザを実装しています。メモリのコストのために、イメージの動的ロードを実装する必要があります(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、メモリ爆発に両方それを試してみてくださいたびに。 Instrumentsでコードを実行しましたが、漏れは報告されていません。 ldViewはistance変数であり、オブジェクトdealloc(これは確実に呼び出されます)のldPageRefでtogheterに割り当て解除されます。
また、NSURLCache sharedCacheをゼロまたはゼロに設定しようとしましたが、それでも起こっています。
私はMemory management guideを読んだことがありますが、everythimgは大丈夫です。 助けてください
try [pool drain] – Vjy