【发布时间】:2010-11-18 00:21:03
【问题描述】:
内存泄漏问题 - NSConcreteData
// to set tip - photo in photo frame
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:pathOfThumbNail]];
UIImage *cellThumbImg;
if([data length]>0){ cellThumbImg=[UIImage imageWithData:data];} else { cellThumbImg=[UIImage imageNamed:@"130X90.gif"]; }
UIImageView *imgView=[[UIImageView alloc]initWithImage:cellThumbImg]; imgView.frame=photoFrame;
(cellThumbImg.size.height>=58 || cellThumbImg.size.width>=58 ) ? [imgView setContentMode:UIViewContentModeScaleToFill] : [imgView setContentMode:UIViewContentModeCenter] ;
[cell.contentView addSubview:imgView];
[imgView release];
我的问题和这个问题很相似,
iPhone - Memory Leak - NSData dataWithContentsOfUrl & UIWebView
甚至,我在我的应用程序完成启动中添加了以下代码,如下所示。 以下代码用于将 sharedCache 内存设置为零容量。它几乎可以消除我的应用程序中的 NSConcreteData 泄漏。但是内存泄漏。
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];
[window makeKeyAndVisible];
}
我无法从堆栈溢出中找到此类问题的任何解决方案。
如果你能回答,我会很感激你。
提前致谢。
【问题讨论】:
-
我遵循@Bkaenk 和@epatelsaid 的方式。但是,存在相同的问题,如下面的问题。 stackoverflow.com/questions/280053/…
标签: iphone cocoa-touch memory-leaks