0

in my iphone App i want add Animation which displays images one after another for that

  imgView.animationImages = [NSArray arrayWithObjects: 

                           [UIImage imageNamed:@"image1.png"],
                           [UIImage imageNamed:@"image3.png"],
                           [UIImage imageNamed:@"image5.png"],
                            "
                            "
                           [UIImage imageNamed:@"image150.png"],nil];

imgView.animationDuration = 13.00;
imgView.animationRepeatCount = 1.0;  
[imgView startAnimating]; 

how to manage images to for for smooth Animation and app could run without crash ?

i have already compressed my image size.

ios
  • 6,134
  • 20
  • 71
  • 103
  • Compressing the image of the image does not make take up less memory when load. To get estimate of the bytes pers image use this forumla" Width x Height x 4. Where 4 is the bytes per color. – rckoenes Aug 11 '11 at 07:09
  • Can you please provide the crash reason which can be found in the console. – Mikayil Abdullayev Aug 11 '11 at 07:16
  • It works for simulator but crashes while running on device – ios Aug 11 '11 at 07:19
  • Show us the device crash logs or keep connect your device with xcode and play around until you don't make it crash and then send that log error. the cause is related to your memory leak. – Praveen-K Aug 11 '11 at 07:21

1 Answers1

2

IMO, since you say that the app is working fine under the simulator and crashes on a device, the most likely cause for the crash is that you are taking too much memory and the OS kills the app (after sending at least one memory warning in my experience).

A very clear sign of it is your app dying without any error messages from the debugger (if you try and run it under the debugger - cmd-Y).

A variant of this behavior is that the OS sends a memory warning, your app unloads some resources (this is done automatically by UIKit for you), and then your app does not find them anymore and crashes. In this case, you should see some meaningful message in the error log.

You could try and reduce the number of images composing your animation to 50 just to see if the crash is there or not; or you could run the app under Instruments to see how memory grows during time and see if the crash is related to a memory peak. By the way: how large are your images? Possibly even 50 could be much...

Another possible reason would be that imgView.animationImages is not retained properly, but I doubt this since you say under the simulator everything works fine.

sergio
  • 68,819
  • 11
  • 102
  • 123
  • Sergio is correct that the cause of your crash when running on the device is using up all the app memory. This is not a "leak" in sense that an object was not released properly, it is a basic problem with the animationImages API which you should never use. You can read more in depth info in my answer to this related question: http://stackoverflow.com/questions/8112698/how-to-do-animations-using-images-efficiently-in-ios/17129053#17129053 – MoDJ Jun 18 '13 at 15:30