Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 9, 2012, 10:37 PM   #1
Feltzem
macrumors regular
 
Join Date: Sep 2009
Game using large amounts of memory

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?
__________________
Macbook Air 13", 1.7GHz i5, 4GB RAM, 256GB SSD
White iPhone 5S, 16GB
Feltzem is offline   0 Reply With Quote
Old Nov 9, 2012, 11:06 PM   #2
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
How are you loading the images?
__________________
dejo is offline   0 Reply With Quote
Old Nov 9, 2012, 11:16 PM   #3
Feltzem
Thread Starter
macrumors regular
 
Join Date: Sep 2009
Quote:
Originally Posted by dejo View Post
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"]],
 (etc x 30) 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.
__________________
Macbook Air 13", 1.7GHz i5, 4GB RAM, 256GB SSD
White iPhone 5S, 16GB
Feltzem is offline   0 Reply With Quote
Old Nov 10, 2012, 01:37 AM   #4
Feltzem
Thread Starter
macrumors regular
 
Join Date: Sep 2009
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.
__________________
Macbook Air 13", 1.7GHz i5, 4GB RAM, 256GB SSD
White iPhone 5S, 16GB
Feltzem is offline   0 Reply With Quote
Old Nov 10, 2012, 01:56 PM   #5
idelovski
macrumors regular
 
Join Date: Sep 2008
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.
__________________
GlideShow - Slideshows with images from Reddit, Facebook, Flickr, Dropbox, SkyDrive & Google.
idelovski is offline   0 Reply With Quote
Old Nov 10, 2012, 02:24 PM   #6
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
The amount of memory used by an image is wxhx4. It's not the same as the size of the image on disk.
PhoneyDeveloper is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Tags
ios, ipad, iphone, objective-c, xcode

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
iPhone sending large amounts of data???? pTacRP iPhone 6 Feb 14, 2014 10:23 AM
Looking for wholesale buyers or someone who buys in semi large amounts mplayers2005 Buying Tips and Advice 0 Sep 4, 2013 04:45 PM
AT&T says I use large amounts of data, iPhone 5 says otherwise ben824 iOS 6 7 Apr 24, 2013 09:55 PM
Backup Large amounts of Data Rmafive Mac Pro 25 Jun 15, 2012 07:21 PM

Forum Jump

All times are GMT -5. The time now is 03:12 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC