Vip*_*jay 0 memory iphone ipad ios
我正在开发一个小型游戏应用程序Uikit + Uiimages.在正常情况下我的应用程序运行没有任何问题.但是当我轻率地使用时,它会因错误而崩溃
<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).
Run Code Online (Sandbox Code Playgroud)
我将在使用完成后发布所有图像视图和视频.我用泄漏工具测试了我的应用程序.也没有泄漏.没有警告,没有潜在的泄漏等......
我搜索了一个很好的答案,但我还没有得到适当的答案.谁知道答案,请回复.我在下面发布了一些代码.
- (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];
}
Run Code Online (Sandbox Code Playgroud)
尝试initWithContentsOfFile在整个项目中使用加载图像而不是UIImage imageNamed.
imageNamed如果您有太多可能导致严重问题的图像,则会自动释放,Apple本身建议减少使用自动释放的对象.
iPhone OS注意:因为在iPhone OS上,应用程序在更受内存限制的环境中执行,所以在应用程序创建许多对象的方法或代码块(例如,循环)中不鼓励使用自动释放池.相反,您应该尽可能明确地释放对象.
从缓存目录中读取图像数据时出现相同的错误.
当您的图像包含在App-Project中时,afzal的建议是最好的解决方案.
但是直接从Cache文件夹中读取它时,比不使用
[UIImage initWithContentsOfFile:<image-file-path>];
特别是当您从Cache-Folder中加载像一堆图像时,因为它可能会破坏您的一些图像,并且它们可能看起来只有一半只加载了一半.像下面一样加载图像数据
NSData *data = [NSData dataWithContentsOfFile:<image-file-path>];
UIImage *image = [UIImage imageWithData:data];
Run Code Online (Sandbox Code Playgroud)
这对你的任何图像都不会有任何损坏.
我猜,它是因为一次打开了许多输入流.