UIImage的动画造成应用程序崩溃/内存泄漏 [英] UIImage Animation Causing App to Crash / Memory Leaks

查看:490
本文介绍了UIImage的动画造成应用程序崩溃/内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一个UIImage动画和它使用的应用程序造成对不同的用户提供了大量的内存泄漏和崩溃。

I'm using a UIImage animation and it is causing numerous memory leaks and crashes for different users using the application.

下面是我的code。我是preloading在viewDidAppear该组的两个动画

Below is my code. I am preloading the set of two animation in viewDidAppear

pointsView.image = [UIImage的imageNamed:@C72.png];

pointsView.image = [UIImage imageNamed:@"C72.png"];

    NSMutableArray *menuanimationImages = [[NSMutableArray alloc] initWithCapacity:21];
    NSString *imageName;

    for( int aniCount = 0; aniCount < 72; aniCount++ )
    {
        imageName = [NSString stringWithFormat:@"C%d.png", aniCount];
        [menuanimationImages addObject:[UIImage imageNamed:imageName]];
    }

    pointsView.animationImages = menuanimationImages;

    pointsView2.image = [UIImage imageNamed:@"I72.png"];

    NSMutableArray *menuanimationImagess = [[NSMutableArray alloc] initWithCapacity:21];
    NSString *imageNames;

    for( int aniCounts = 0; aniCounts < 72; aniCounts++ )
    {
        imageNames = [NSString stringWithFormat:@"I%d.png", aniCounts];
        [menuanimationImagess addObject:[UIImage imageNamed:imageNames]];
    }

    pointsView2.animationImages = menuanimationImagess;
}

我然后使用运行动画

I am then running the animation using

pointsView.animationDuration = 3.11;
pointsView.animationRepeatCount = 1;
[pointsView startAnimating];

有什么建议?

推荐答案

请阅读我的博客文章有关此主题:视频和内存使用上-IOS-设备。问题的根源在于,你根本就没有在同一时间加载到主存这么多的图像。您需要根本就没有使用UIImageView.animationImages API,它打破严重和诱惑开发商陷入编写糟糕code时,在设备上运行,这将崩溃。

Please read my blog post about this subject: video-and-memory-usage-on-ios-devices. The root of the problem is that you simply cannot have this many images loaded into main memory at the same time. You need to simply not use the UIImageView.animationImages API, it is badly broken and lures developers into writing bad code that will crash when run on the device.

这篇关于UIImage的动画造成应用程序崩溃/内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆