views:

138

answers:

1

i have an application which takes "live bytes" up to 3mb. The application showing memory warnings and it will crash continously. when i use object allocation tool i can see the live bytes.im using imageWithContentsOfFile in many places. i can see NSConcreteData object is taking more momory.what is the reson for that? may i know how much memory is allowed to an application.

A: 

You can't really know how much memory you're allowed to use, but in general you're fine up to 20mb on iPhone/iPod devices. However, your app can be killed not only for using too much memory, but for failing to decrease memory usage when warnings are issued. So even if you're not using all that much memory, if the system detects that you don't release any memory when getting memory warnings, your app might be shut down. At least that's my experience, maybe others have more detailed knowledge about what's going on.

imageWithContentsOfFile: has a built-in caching mechanism, so if you're loading the same images over and over, there should be very little overhead.

EDIT: imageWithContentsOfFile: does not cache images. The method imageNames: does cache images, and it's the only image creation method that does.

Felixyz
thanks for ur reply. how can i clear the cache?
Allen
The image cache is taken care of by the libraries. But if you're sure you only have 3mb live memory (use the Activity Monitor tool to be sure), the problem might be something else. When you get memory warnings, views get deallocated and it's easy to get your view controllers into a state where unexpected bugs show up. I've had that kind of problem many times. The problem might not be memory, but the way view controllers or other code fail to handle the situation where views must be reloaded. If they depend on things getting initialized after the view is loaded for example.
Felixyz
yes im sure i have only 3mb live bytes. can you explain it detail?
Allen
As far as I know imageWithContentsOfFile doesn't have a caching mechanism, it just returns an autoreleased UIImage object. UIImage's +imageNamed is the one having the cache.
Brainfeeder
@Brainfeeder: You are right, imageWithContentsOfFile: doesn't cache the images, only imageNamed: does. It's there in the documentation :)
Felixyz