views:

66

answers:

2

Ok, so here's my problem. My iPhone app is 1.2MB on disk. Granted I have a bunch of Images for the GUI buttons and backgrounds, etc. In-memory, my app takes up a whopping 15MB!

That means if I then take a picture with the camera, 8MB default, it gives a memory warning (several) even before the picker calls its delegate!

How can I tell what is grabbing so much memory, and how to remove it? I've removed all of my debugging symbols and added [-Os], but it still takes up a huge amount of memory!

--- Edit ---

My apps are up at strongfortressgames.weebly.com - The app "Thunderclash" takes up 15 MB!!! it is a stupid little app! How can I make these smaller?

+1  A: 

The only time memory warnings are bad is if there is no memory to free up. Then they become memory failures and the application terminates.

Once you load compressed images like png and jpg into memory they are decompressed and often take up 10x the size. When you use [UIImage imageNamed:] it caches the images in memory. This is implicit with any images loaded by a xib. When it receives a memory warning, it releases images in the cache.

Any views you have which are not images may have the rendered contents cached in memory. When a memory warning is received, the caches are cleared unless they are currently displayed. Entire view hierarchies may also be released by view controllers that are not currently displayed.

Memory warnings are a normal part of the application runtime. They do not indicate memory leaks. They simply tell you and the system that idle memory should be released.

While it might be an admirable goal to run with no memory warnings, you generally need to allocate memory and it is more efficient to keep it around unless it is needed for other things. When an image is purged from the memory cache, it must be read from disk next time.

If there is an image that you know will only be needed once or very rarely, you can load it by a call besides [UIImage imageNamed:] to avoid caching. For example a secondary splash screen that is only loaded as the application launches.

drawnonward
Most of the images I'm loading come from either the Bundle, or from the user taking a picture or loading from the library.The problem I think I'm having is that taking a picture with the camera - I lose the picture before the delegate gets to save it. It seems to clean house before I can write it to disk.
Stephen Furlani
Ah, I missed that from the question. I have opened enough images at once to exceed the 24MB or so that you are having troubles at. I do not have much more to offer, but maybe setting a breakpoint in `[UIImage dealloc]` would help if it was not autoreleased. My gut feeling is that it is only partly related to the memory warning and something else is wrong. Good luck.
drawnonward
A: 

Ok, if your app isn't huge on disk/on cart, that means that you have some very large memory allocations going on internally in your app. Put a break or log tracker on your memAlloc/new() functions and see what is eating your space. Decompressed, large GUI components could be a culprit as could very large, buffered sound files. Still, without that log trace, we can only guess. Go to the source instead.

Michael Dorgan