简体   繁体   中英

ImageIO: CGImageRead_mapData 'open' failed error = 24 (Too many open files)

I am developing a small game app using Uikit + Uiimages . In the normal condition my app is running without any problem . but when i use rashly it will crash with the error

<Notice>: ImageIO: CGImageRead_mapData 'open' failed '/var/mobile/Applications/01E69C96-CF79-466F-93AB-3A6752AF1295/PictureBook.app/NextPage.png'

<Notice>: error = 24 (Too many open files).

I am releasing all the image views and videos after usage is complete. I tested my app with leak tool. There is no leaks also. No warnings, no potential leaks etc...

I searched for a good answer, but i didn't get the appropriate answer yet. Anyone knows the answer , please reply. I posted some of the codes below.

- (NSMutableArray *)flowerArray {

if (!_flowerArray) {

_flowerArray = [[NSMutableArray alloc]init];

for (int i = 1; i <= 5; i++) {

UIImage *flowerIm = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"01_Flower_0%d.png",i] ofType:nil]];

[_flowerArray addObject:flowerIm];

[flowerIm release];

}

}

return _flowerArray;
}


-(void)flowerImagesAnimate {

self.flowerImage.animationImages = self.flowerArray;

self.flowerArray = nil;

self.flowerImage.animationDuration = 1.0;

self.flowerImage.animationRepeatCount = 3;

[self.flowerImage startAnimating];

}



-(void)playerPrepare
{

[self.view addSubview:[self.presentView playerPrepare]];

}
-(void)wakeUPPanjo
{
NSString *url = [[NSBundle mainBundle] pathForResource:@"01_Anim" 
ofType:@"mp4"];

NSURL *movieURL = [NSURL fileURLWithPath:url];



self.presentView.player = [[MPMoviePlayerController alloc] 
initWithContentURL:movieURL];




[[NSNotificationCenter defaultCenter] 
addObserver:self
selector:@selector(movieFinishedCallback 
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.presentView.player];

[self.presentView.player prepareToPlay];

[self performSelector:@selector(playerPrepare) withObject:nil afterDelay:0.5];

wakeUpTimer = nil;


}


-(void)viewLoad
{

wakeUpTimer = [NSTimer scheduledTimerWithTimeInterval:videoDelay target:self selector:@selector(wakeUPPanjo) userInfo:nil repeats:NO];

[self performSelector:@selector(flowerImagesAnimate) withObject:nil afterDelay:flowerPopupDelay];
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.

[self performSelectorOnMainThread:@selector(viewLoad) 
withObject:nil 
waitUntilDone:false];
}

Had the same error when reading the image-data from my cache directory.

When your Image is contained in the App-Project, than afzal's suggestion is the best solution.

But when reading it directly from the Cache Folder, than do not use

[UIImage initWithContentsOfFile:<image-file-path>];

especially when you load like a bunch of Images from the Cache-Folder, because it might break some of your images and they could look like some were only half loaded. Load the Image Data like following

NSData *data = [NSData dataWithContentsOfFile:<image-file-path>];
UIImage *image = [UIImage imageWithData:data];

This will most like not look damaged to any of your images.

I guess, its because of opening to many input-streams at once.

Try to use initWithContentsOfFile in your whole project for loading images instead of UIImage's imageNamed . imageNamed is auto released if you have too many images that can lead to serious problems, apple itself recommends to reduce the use of auto released objects.

iPhone OS Note: Because on iPhone OS an application executes in a more memory-constrained environment, the use of autorelease pools is discouraged in methods or blocks of code (for example, loops) where an application creates many objects. Instead, you should explicitly release objects whenever possible.

Run sudo fs_usage -f filesys PictureBook . In the second column, files should "open" and "close", but your app has too many "open" and too few "close" because you are opening files too fast or leaking file descriptors. Maybe you are not retaining _flowerArray and it is recreated everytime? It is unclear. Look for the offending files and add some logs around.

If you were used UIImage's imageNamed instead initWithContentsOfFile , files would be cached and reused, and it wouldn't be so prone to crashing, but anyway, it is highly likely that you are leaking/opening too fast.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM