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];
}
Try to use
initWithContentsOfFilein your whole project for loading images instead of UIImage’simageNamed.imageNamedis 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.