typical memory usage of an iphone app - iphone

According to Instruments 'Net Bytes' of my app are never more than 2MB yet sometimes I receive memory warning and the app crashes because some views on the stack are unloaded by force.
I'd like to know what is the typical memory footprint where system would not send you memory warning and unload the views ?
I have so far tried this on OS 3.1.2 on iphone 3GS and 3G and with 3G giving warning almost 80% of the time I test the app on it.

The problem isn't that you're using to much memory. It might be some other application that's using the memory and causing your app to receive a memory warning.
The problem probably is that your not setting your views to nil on viewDidUnload.

Related

iPhone iOS what is the most accepted way of dealing with memory warnings?

I've been surprised that iOS 5.1 does not manage memory quite as I expected. When the device is running a lot of apps, it appears that iOS does not kill memory hogging apps in the background, but sends memory warning to my own app as well.
For example showing a UIImagePicker crashed the app on two test devices. Double tapping the home key and killing some of the background apps prevents the app from receiving the memory warning and crashing.
I'm wandering if iOS would not free up memory for me, is it acceptable to show some sort of alert view notifying the user that the memory is low and some of the background tasks have to be killed?
I'm at a loss of how to deal with such events - does it take time for iOS to clean up some memory (while apps respond to memory warnings)?
iOS does a lot of stuff before bothering you with memory warnings, including killing backgrounded Apps. Since iOS 5, iOS is even going to annoy you as less as possible with memory warnings, meaning that you only get one if there really is a need for you to get rid of stuff that is using memory but not needed right now (and that you can safely recreate in the future without taking hours for it). If your App crashes without giving you a memory warning first, chances are that you allocated so much memory that the system can't tell you that its running out of memory before it decides to kill you, the reason for this is that the memory warning is scheduled on the runloop of the main thread and until you give the runloop time to do another iteration, you won't receive the warning.
Also, Apple doesn't like you to tell the user that there is a memory problem; Its your App that has to deal with it, not the user! So its very very likewise that your App gets rejected if a memory warning comes up while the review team is reviewing your app (rumor says that they send these warnings to test how your App reacts to them)
Soo, to sum it up: iOS does work like you expected by killing what it can and even shutting down other system daemons, only after this happening you will be notified that memory is low. The correct way to respond to these warnings is to free up as much memory as you can, start with the big stuff that can be easily recreated in the future (eg. if your app shows loads of pictures but not all are visible at a time, throw away the ones that aren't visible right now). Telling the user is the wrong way to deal with the problem and Apple doesn't like it, so try to solve the problem on your end.

Need more memory for my iPad app

I am working on a mail client on iPad (similar to that of the default app client) and using core data framework as a cache to increase performance . My app uses around 4.5 - 5 MB of heap memory and then it crashes because of memory overflow (detected this using allocation instrument). If I try to reduce memory my performance becomes very slow and sluggish because I am not able to cache my views, data structure (which store folders and all the mails) and tableviews.
I have checked my crashLogs and I see jettisoned written in front of my App which confirms that OS has forcefully closed my App!
I have used instrument to detect these limits. Please find the attached image here
This is a snapshot my recordings just before the app crashes.
I have tested my app on simulator and it stabilizes itself at 6 - 7 MB of heap memory.
Is there any way so that I can ask OS for more memory or avoid crash with a little redesign in my code.
Any suggestions or help would be highly appreciated.
6-8MB of memory should never be a problem. Likely you are either trashing memory or if you are running a debug version and have Zombies turned on, the default is to never delete the zombies. NSZombiesEnabled=YES and NSDeallocateZombies=NO will appear to leak memory as nothing is ever deleted.

Program received signal: “0”: If this is caused by memory leaks why do I not receive memory warnings?

After a few minutes of intense use my app quits with "Program received signal: “0”." As far as I've been able to determine this signal is caused by excessive memory usage. What puzzles me is that I often don't get any memory warnings at all prior to the app crashing. If I'm using too much memory shouldn't the OS emit a memory warning before booting me?
The only alternative that I can think of is that I'm requesting such a huge single block of memory that the OS just balks and boots me immediately, but that doesn't seem to be the case either: the crash often occurs in situations where there's no massive allocations of memory.
What am I not understanding about how memory warnings work or about signal 0?
P.S. - The app is an iPad only app compiled with the 4.3 SDK and targeting iOS 3.2 and above.

unable to allocate 4 buffers of 20 mb of memory in app on ios 4 but could in ios 3

I wrote an app compiled against ios 3 that would easily allocate up to 100 mb of memory for image processing purposes. However, when that same app was compiled against the ios 4 sdk, I found that it crashed when many apps were open in the background. When I kill the background apps, the application then runs fine. I reduced the memory usage to 70mb, and I still find that it crashes when many background apps are open.
Why are apps compiled against ios 3 are able to get more memory on phones running ios 4?? Is there something special you need to do to tell the ios 4 OS to give you more memory? Is there a way to cause background apps to be closed in order to allocate more memory for your app?
BTW, the app uses Core Graphics to some extent. Would that affect the apps ability to request memory?
Given your description, your app was pushing the memory allocation envelope on iOS 3.x, but goes too far in 4.x, likely because the newer operating system is using more memory.
The only solution is to use less memory. It really is that simple. You can't control how much memory the underlying OS will use to run processes. The only thing you can control is your app and how much memory you allocate so you don't crash.
It's unlikely that you "find that it crashes when many background apps are open". Almost certainly the system is terminating your app for using too much memory and ignoring any warnings to that effect. (I guess you could crash by trying to allocate more memory than the system has available, but that would have to be a very large allocation made in a large chunk).
Tell us more about how you're allocating this memory. Are you paying attention to low memory warnings?

iPhone Memory warning level=2

I have an app that stacks quite a nice amount of views on top of each other.
At some point I receive a Memory warning level2 (which is kind of expected).
The thing is, when I run Instruments, I don't have any memory leaks and the app takes up something like 9-10MBs... which is not that much, I'd say?
Question is: how much memory can an app consume, a.k.a. how much RAM does the iPhone have?
I know that I can respond the the receivedMemoryWarning and free up some memory - but this would mean that I'd have to get rid of some of the views, which is not the solution I'm looking for...
The app didn't crash so far - but I'm concerned that it might crash on other user's iPhones...
An application can use 30-40 MB of real memory or greater then this and there will not be a problem. When you are getting a memory warning level-1, till then there is not a problem, but if you get memory warning level-2, then the app might or will crash after some time.
solution is, when you get memory warning level-2, inside your delegate method, release some memory which you are not using currently.
You app won't crash anyone's iPhone. The system will just kill your app. Anyway 3GS is rumored to have 256Mb while iPhone 4 has 512Mb. It still won't matter because when you receive a warning you better comply.
Try reducing the amount of views you have or unload the ones which the user can't see.