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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:59:46+00:00 2026-05-18T00:59:46+00:00

It’s a simple app that takes 30 pics from my Resources folder, puts them

  • 0

It’s a simple app that takes 30 pics from my Resources folder, puts them into an NSMutableArray during viewDidLoad, and then changes the pic based on accelerometer data. I have a UIImageView from IB covering the whole view, and when the accelerometer updates its info, it swaps the uiimageview.image to a diff pic. Works for about 10 seconds, and then crashes with this:

Program received signal:  “0”.
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib")

After looking around on here it sounds like it’s a memory leak. Here’s the code I’m using:

Interface:
{
    UIAccelerometer *accel;
    IBOutlet UIImageView *pic;
    NSMutableArray *picArr;
}

Implementation:

- (void)viewDidLoad
{   
[super viewDidLoad];

picArr = [[NSMutableArray alloc] init];  //array of pics to be used
NSString *path = [[NSString alloc] init]; //dynamic path of images to save to array

for (int i = 1; i <= 30; i++)
{
    path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"nativity_test_%i", i] ofType:@"jpg"];

    [picArr addObject:[[UIImage alloc] initWithContentsOfFile:path]];

}

accel = [UIAccelerometer sharedAccelerometer];
accel.delegate = self;
accel.updateInterval = 0.5f;

[path release];

pic.image = [picArr objectAtIndex:15];
}

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{

if(acceleration.y < 0.0f) //goes thru the tilted left pics
{
    for (int i = 0; i <= 15; i++)
    {                       
        if( acceleration.y >= (-(15.0f-(double)i)/30.0f) && acceleration.y <  (-(14.0f-(double)i)/30.0f) )
        {
            pic.image = [picArr objectAtIndex:i+1];
        }
    }
}

else if(acceleration.y > 0.0f) //goes thru tilted right pics
{       
    for (int i = 1; i <= 14; i++)
        if( acceleration.y > ((double)i/30.0f) && acceleration.y <= ((double)(i+1)/30.0f) )
        {
            pic.image = [picArr objectAtIndex:i+15];
        }
}
}

Please let me know if I left out any pertinent info.

  • 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-18T00:59:47+00:00Added an answer on May 18, 2026 at 12:59 am

    This is not a crash caused by a memory leak, but by an overrelease of memory. Your crash is caused by this line:

    [path release];
    

    Remove that line and you should be fine. For some values of fine, anyway; most of what George says also applies.

    The reason is that the path being released will be this one:

    path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"nativity_test_%i", i] ofType:@"jpg"];
    

    That’s an object with an effective retain count of zero. While it has a positive retain count, it’s already been autoreleased and will be released when you return to the main event loop.

    You should also remove this line:

    NSString *path = [[NSString alloc] init]; //dynamic path of images to save to array
    

    The reason is you’re assigning the result of pathForResource to path, never actually using it. You’ll need to declare path as a variable, of course. I suggest changing the pathForResource line to this:

    NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"nativity_test_%i", i] ofType:@"jpg"];
    

    This is a smart change, as there’s no reason you’d need this outside of the loop.

    You should also fix this line:

    [picArr addObject:[[UIImage alloc] initWithContentsOfFile:path]];
    

    [UIImage alloc] returns an UIImage with an effective retain count of 1. Adding it to an array will increase that to two. If you’re just releasing the array later, this will cause a memory leak. Instead:

    [picArr addObject:[[[UIImage alloc] initWithContentsOfFile:path]] autorelease];
    

    That will mean you’re adding an UIImage with an effective retain count of 0 to the array, which will bump it to 1, making the array the only owner of the object. Later when the array goes away, so will most of the images. (The imageView will also own whichever is assigned to it.)

    Don’t be frustrated by this stuff: one day soon you’ll just suddenly get it and wonder why it ever caused you headaches. 🙂

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

Sidebar

Related Questions

No related questions found

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.