Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8181977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:42:11+00:00 2026-06-07T00:42:11+00:00

we’re loading about 30 full 320 x 480 images into an animations array. These

  • 0

we’re loading about 30 full 320 x 480 images into an animations array. These images are very small in size at about 5 – 7Kb per images. The problem is when we run the loop to populate an array for the images, it seems to pause the entire app while this array get’s populated. Is there perhaps a way to load this mutable array with the images in a separate thread or something to allow the array to populate without hurting performance? Thanks

    NSMutableArray *totalAnimationImages  = [[NSMutableArray alloc] initWithCapacity:numOfImages];

for(int i = 1; i < numOfImages; i++) {
    [totalAnimationImages addObject:[UIImage imageNamed:
                                     [NSString stringWithFormat:@"%@%d.png", image, i]]];
}

annImage.animationImages = totalAnimationImages;
annImage.animationDuration = speed; //.4 second
annImage.animationRepeatCount = 1; //infinite loop

[annImage startAnimating]; //start the animation

[totalAnimationImages release];

In working with this issue, and using the threading suggestion provided by shabzco, I’ve come up with the below code to process a loop, changing the image in an image view, with what seem to be absolutely no performance hit. This only holds one image at a time instead of 30 in an NSMutableArray. Just as Richard J. Ross III said, as soon as the animation would start it would be processing all of the images “into a in-memory bitmap format”. This is where the long wait / lag came from. In the below code this is only happening once per image update instead of 30 just to start the animation. I use the while loop with timer in the suggested dispatch thread to keep this timer from effecting the main thread thus potentially creating jerky performance during animations. Please provide feedback on this solution! Thanks

UPDATE: Shabzco suggested that I replace the “ImageNamed” with “imageWithContentsOfFile” to avoid strange memory leaks due to ImageNamed potentially caching images in memory. This was discovered after running xcode profiler and watching the “Real Memory” counter. It became evident that every time an animation ran, the real memory would increase more and more until ultimately the app would crash. After replacing “ImageNamed” with “imageWithContentsOfFile” the issue went away. I’ve updated the below code.

annImage.image = [UIImage imageNamed:@""];
[annImage setAlpha:1.0];
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(concurrentQueue, ^{ 
    NSTimeInterval timeout = 1.00 / speed;   // Number of seconds before giving up
    NSTimeInterval idle = 1.00 / 8;     // Number of seconds to pause within loop
    BOOL timedOut = NO;
    NSDate *timeoutDate;
    for(int i = 1; i < numOfImages; i++) {
        timeoutDate = [[NSDate alloc] initWithTimeIntervalSinceNow:timeout];
        timedOut = NO;
        while (!timedOut)
        {
            NSDate *tick = [[NSDate alloc] initWithTimeIntervalSinceNow:idle];
            [[NSRunLoop currentRunLoop] runUntilDate:tick];
            timedOut = ([tick compare:timeoutDate] == NSOrderedDescending);
            [tick release];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            //annImage.image = [UIImage imageNamed:
            //                      [NSString stringWithFormat:@"%@%d.png", image, i]];
            NSString *filePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@%d", image, i] ofType:@"png"];
            annImage.image = [UIImage imageWithContentsOfFile:filePath];
        });   
    }

    dispatch_async(dispatch_get_main_queue(), ^{
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration: 0.3];
        [annImage setAlpha:0.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView commitAnimations];

    });
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:42:13+00:00Added an answer on June 7, 2026 at 12:42 am

    This will make your for loop happen in a different thread and will start animating once everything has been loaded.

    @autoreleasepool {
            NSMutableArray *totalAnimationImages  = [[NSMutableArray alloc] initWithCapacity:numOfImages];
            dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
            dispatch_async(concurrentQueue, ^{   
                for(int i = 1; i < numOfImages; i++) {
                    [totalAnimationImages addObject:[UIImage imageNamed:
                                                     [NSString stringWithFormat:@"%@%d.png", image, i]]];
                }
                annImage.animationImages = totalAnimationImages;
                annImage.animationDuration = speed; //.4 second
                annImage.animationRepeatCount = 1; //infinite loop
                [annImage startAnimating]; //start the animation
                dispatch_async(dispatch_get_main_queue(), ^{
    
                    [totalAnimationImages release];
    
                });
            });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I have a reasonable size flat file database of text documents mostly saved in
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.