Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
862 views
in Technique[技术] by (71.8m points)

iphone - UIImage Animation Causing App to Crash / Memory Leaks

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

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

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];

Any suggestions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...