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

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

问题描述

我正在使用 UIImage 动画,它导致使用该应用程序的不同用户出现大量内存泄漏和崩溃.

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

下面是我的代码.我正在 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;
}

然后我使用

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

有什么建议吗?

推荐答案

请阅读我关于此主题的博文:video-and-memory-usage-on-ios-devices.问题的根源在于您根本无法将这么多图像同时加载到主内存中.您只需不要使用 UIImageView.animationImages API,它已严重损坏并诱使开发人员编写在设备上运行时会崩溃的错误代码.

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天全站免登陆