Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Feltzem

macrumors regular
Original poster
Sep 20, 2009
107
0
I'm developing an iOS game that has shooting and reload animations for weapons. Per gun, the total of the images that make up the animation is only about 10MB, yet when they load on the device (retina iPad) the app increases in memory use by about 400MB. Why is this?

When the shooting view loads, it loads the images into two arrays (fire and reload), and plays the animation over in 0.1 seconds before it loads so that there is no delay when shooting or reloading. There is little else in the view that would be using large amounts of memory.

What would you recommend I do to decrease the amount of memory the game is using?
 

Feltzem

macrumors regular
Original poster
Sep 20, 2009
107
0
How are you loading the images?

Like this: ('rev' is the UIImageView the animation plays in, gunanimload is the array)

Code:
- (void)viewDidLoad
{
    [super viewDidLoad];

myQueue = dispatch_queue_create("com.dubzem.shooting", NULL);
    dispatch_async(myQueue, ^{
    
    gunanimload = [NSArray arrayWithObjects:
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"rev0001" ofType:@"png"]], 
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"rev0002" ofType:@"png"]],
 [B](etc x 30)[/B] nil];

rev.animationImages = gunanimload;
    rev.animationDuration = 0.10;
    rev.animationRepeatCount = 1;
    [rev startAnimating];});
}

And when the Fire button is tapped:

Code:
type.animationImages  = gunanimload;
    type.animationDuration = 0.5;
    type.animationRepeatCount = 1;
    [type startAnimating];

Reload is the same, except with 41 images in the array.
 

Feltzem

macrumors regular
Original poster
Sep 20, 2009
107
0
Is this an efficient way to load and play a PNG animation? I'm wondering why it's using so much memory even though the images are small in size.
 

idelovski

macrumors regular
Sep 11, 2008
235
0
I warmly recommend you use Instruments. If you really have more than ten times greater memory usage than what you'd expected, you should stop guessing and start with the Instruments.

There you'll see the objects that occupy a lot of memory. 400MB on iOS device is an incredible amount of memory. You'll see malloc blocks too, and guessing where they come from may take a bit more time but their size should point you in the right direction.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.