我在UIImage中发生严重泄漏。你可以帮我吗?内存泄漏uiimage
-(UIImage*)getImage{
return [self getForrrrImage];
}
-(UIImage*)getForrrrImage{
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
UIImage *imageResult=nil;
if(index>=0 && index<[imagesPatchs count]){
NSString *key=[imagesPatchs objectAtIndex:index];
if(small)
imageResult=[savedImagesDic objectForKey:key];
if(!imageResult){
NSRange range=[key rangeOfString:@"test_bg"];
if(range.location!=NSNotFound){
NSString *filePath1;
if(small){
NSString *str=[[NSString alloc] initWithFormat:@"%@_small",key];
filePath1=[[NSBundle mainBundle] pathForResource:str ofType:@"jpg"];
[str release];
}
else
filePath1=[[NSBundle mainBundle]pathForResource:key ofType:@"jpg"];
if(filePath1){
imageResult=[self createImageFromFile:filePath1];
if(small){
[savedImagesDic setObject:imageResult forKey:key];
}
}
}
else{
NSString *filePath;
if(small)
filePath=[[NSString alloc]initWithFormat:@"%@/%@_small.png", DOCUMENTS_FOLDER, key];
else
filePath=[[NSString alloc]initWithFormat:@"%@/%@.png", DOCUMENTS_FOLDER, key];
if([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
imageResult=[self createImageFromFile:filePath];
if(small){
if(imageResult){
[savedImagesDic setObject:imageResult forKey:key];
[imageResult release];
}
else {
imageResult=[UIImage alloc];
}
}
else{
if(!imageResult)
imageResult=[UIImage alloc];
}
}
[filePath release];
}
}
}
else
imageResult=[UIImage alloc];
[pool drain];
return imageResult;
}
-(UIImage*)createImageFromFile:(NSString*)filePath{
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
UIImage *imageResult=nil;
NSData *data=[[NSData alloc]initWithContentsOfFile:filePath options:NSUncachedRead error:nil];
imageResult=[[UIImage alloc] initWithData:data] ; ----->Heavy memory leak
[data release];
[pool drain];
return imageResult;
}
getForrrrImage < - 这么多rrrrrrr的特殊含义? – Raptor
这是肮脏的?不妨猜一猜。 – nil
为什么你需要写NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];在每一个功能? – Maulik