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

  • SEARCH
  • Home
  • 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 4022116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:26:07+00:00 2026-05-20T10:26:07+00:00

Dealing with an animation of large images, you can do this: Simply alloc memory

  • 0

Dealing with an animation of large images, you can do this: Simply alloc memory for each of the large images…

NSArray *imagesForLargeAnimation;

#define IMG(X) [[UIImage alloc] \
  initWithContentsOfFile:[[NSBundle mainBundle] \
    pathForResource:@X ofType:@"tif"]]

imagesForLargeAnimation  = [[NSArray alloc] initWithObjects:
                    IMG("01"),
// (since we are allocing that image, of course we must release it eventually.)
                    IMG("02"),
                    IMG("03"),
                    ....
                    IMG("42"),
                    nil];

animationArea.animationImages = imagesForLargeAnimation;
//blah blah...

Later, once the animation has been stopped and is no longer being shown onscreen, to clean up the memory you’d have to do this:

-(void) cleanUpTheMemoryInTheBigAnimation
 {
 //blah blah..

 // for each of those big images in the array, release the memory:
 for (UIImage *uu in imagesForLargeAnimation)
    [uu release];

 // release the array itself
 [imagesForLargeAnimation release];
 imagesForLargeAnimation = nil;

Now, this all works perfectly and efficiently, it will not leak nor overuse memory if you repeatedly use different large animations.

The only problem is, of course you get the clang warning: “Potential leak of an object allocated on line 69”, indeed you get scores of those warnings, one for each alloc.

What’s the best idiom to avoid these warnings — and make it safer and tighter?

Does anyone know?

For example, if you use autorelease, thus, in the code example above you’d use autorelease in the IMG define…

…in fact, when you release the NSArray (ie, [imagesForLargeAnimation release] ) … at that point it will autorelease all the objects in the array? Is that correct? Or??

(Or should I be using some sort of newBlah function to put the images in, or .. ??)

If anyone knows the correct approach here to avoid the “potential leak”, thanks!!!

{PS a reminder to basically never use imageNamed:, it’s hopeless: it’s only suitable for small UI-usage-type images. Never use imageNamed!}

  • 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-05-20T10:26:07+00:00Added an answer on May 20, 2026 at 10:26 am

    You don’t need to keep the images retained – the NSArray will do that for you.

    Try this :

    #define IMG(X) [[[UIImage alloc] \
      initWithContentsOfFile:[[NSBundle mainBundle] \
        pathForResource:@X ofType:@"tif"]] autorelease]
    

    and you don’t now need this code :

    // for each of those big images in the array, release the memory:
    //for (UIImage *uu in imagesForLargeAnimation)
    //    [uu release];
    

    FYI (1) :

    Were you to use imageNamed you would not get a warning because imageNamed returns already autoreleased objects but alloc/initWithcontentsOfFile does not 🙂


    FYI (2) :

    There is a method on NSArrays which performs a selector on all the objects :

    [imagesForLargeAnimation makeObjectsPerformSelector:@selector(release)];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm dealing with this situation : I have a color animation script which targets
The table I'm dealing with it potentially larger than available memory (let's say 10GB)
I am dealing with a large codebase that has a lot of classes and
I'm dealing with a problem here. There's this view that I use to see
I'm dealing with OpenCV and have some memory management questions from their DFT example
Dealing with an employee that went over my head
When dealing with small projects, what do you feel is the break even point
I frequently have problems dealing with DataRows returned from SqlDataAdapters . When I try
I'm dealing with a MySQL table that defines the JobName column as UNIQUE. If
I am dealing with MySQL tables that are essentially results of raytracing simulations on

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.