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 836941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:03:53+00:00 2026-05-15T05:03:53+00:00

I am changing the image in UIImageView based on accelerometer input. The images are

  • 0

I am changing the image in UIImageView based on accelerometer input. The images are stored in an array.
The application runs fine for a while and then crashes.

warning: check_safe_call: could not restore current frame

  1. I am not using “UIImage ImageNamed” method when populating the array.
  2. The total size of all images is around 12 Mb. But individual images are very light (<100 kb) and i am using only one image at a time from the array.
  3. Just in case there are any autoreleases, I have allocated a NSAutoreleasePool in view did load and am draining it in the didReceiveMemoryWarning method (which does get called 2, 3 times before the app crashes?).

Following is the code that creates images array:

    //create autorelease pool as we are creating many autoreleased objects
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSMutableArray *finalarr = [[NSMutableArray alloc] initWithCapacity:9];

NSLog(@"start loading");
for(int y = 0; y < 100; y+=10)
{
    NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:10];
    for(int x = 0; x < 10; x++)
    {
        NSString *imageName = [[NSString alloc] initWithFormat:@"0%d",y + x];

        UIImage *img = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]];
        [arr addObject:img];

        [imageName release];
        [img release];
    }
    [finalarr addObject:arr];
    [arr release];

}

NSLog(@"done loading");
// Override point for customization after app launch
viewController.imagesArray = finalarr;
[finalarr release];
//retain the array of images
[viewController.imagesArray retain];

//release the aurtorelease pool to free memory taken up by objects enqued for release
[pool release];

As the app runs smoothly for a while, which means array creation is definitely not the problem.

After this the following method is called from [accelerometer didAccelerate]

-(BOOL)setImageForX:(int)x andY:(int)y
{
[self.imageView setImage:(UIImage*)[(NSArray*)[self.imagesArray objectAtIndex:y] objectAtIndex:x]];
return TRUE;
}

So the only code being executed is the “UIImageView setImage”. But no objects are being created here.

Please let me know if the code seems to have any leaks or i am doing something wrong.

Thanks,
Swapnil

  • 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-15T05:03:53+00:00Added an answer on May 15, 2026 at 5:03 am

    NSAutoreleasePool should be allocated and released in the same method. Allocating it in one place and releasing it in another is usually very bad (the example code you pasted uses it correctly however)

    Loading images into memory will decompress them; a 100KB compressed PNG could easily be 2MB uncompressed.

    You also seem to have an extra retain call that shouldn’t be there: [viewController.imagesArray retain]; (I assume the imagesArray property is marked copy or retain and not assign)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 411k
  • Answers 411k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm assuming that Freeagent::Base.site is retuning 'https://XXXXX.freeagentcentral.com'. In which case,… May 15, 2026 at 7:56 am
  • Editorial Team
    Editorial Team added an answer public Boolean Compile(String content, ref string errors) Do you want… May 15, 2026 at 7:56 am
  • Editorial Team
    Editorial Team added an answer Set the "Transparancy Key" property and the "BackColor" property of… May 15, 2026 at 7:56 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.