iPhone memory management

Posts: 7
Joined: 2009.03
Post: #1

I am making a 2d game using Texture2D from Crashlanding example.

I am pretty much almost at the end of development. I am loading loads of graphics = menus, loading pages and common game graphics (ie. gui, enemies...) etc and before I cn even load game graphics (background 700x700 png)+ 1024x1024px png) which differs from level to level, Instruments is showing about 28 mb of allocated memory. Then I release the stuff I don't need (menus...) and load game graphics(Instruments shows around 38mb). After level ended I release game stuff and load menus again, BUT Instruments shows around 32 mb (which is more than it was before...). So after I load another game graphics Instruments shows 44... So I can never release all of the memory and when testing it on iPhone it always crashed when trying to load 3rd level.

I load the images like this:
_textures2[kBack] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"back_deepspace.png"]];
and release it after:
[_textures2[kBack] release]

Is there any way of releasing all memory and perhaps load it all over again?

ANY help will be much appreciated, because I spent over 3 months on this game and this memory problem drives me mad!

Quote this message in a reply
Posts: 283
Joined: 2006.05
Post: #2
There was a recent thread where it was shown that imageNamed causes UIImage to cache the image. Using imageWithContentsOfFile solved the problem and resulted in significantly reduced memory usage in some cases.

Try searching for that thread for more info.

(Make sure you're clearing the autorelease pool too - by default you will be but if you're using some strange run-loop system you'll need to do it yourself)
Quote this message in a reply
Posts: 7
Joined: 2009.03
Post: #3
thanks so much man, I have done some testing and it seems it fixes the problem!!!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Data Management ajrs84 5 5,887 Mar 31, 2012 08:32 PM
Last Post: OneSadCookie
  Game State Management Mattonaise 6 9,874 Apr 16, 2011 10:18 AM
Last Post: Mattonaise
  bloody iPhone memory problem again(opengl es, texture2d) mlady 1 4,592 Apr 16, 2009 09:54 AM
Last Post: savemeanegg
  iPhone OpenGL Texturing / Memory fungos 4 9,091 Nov 11, 2008 05:55 AM
Last Post: fungos