Need more memory for my iPad app - iphone

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.

Related

Memory Management/Instruments on the iPhone

I'm developing an RSS reader type iPhone application and it is nearing completion, however I upgraded to Xcode 4 with iOS 4.3 yesterday and I have run into some serious memory issues. My App now frequently gets memory warnings, I'm handling didReceiveMemoryWarning, and releasing all my cached images etc, but this does not provide a good user experience. I've also been using Instruments in an attempt to diagnose the problem, but this has been bringing up more questions then answers.
• Does the SDK 4.3 use more memory ? I wasn't receiving memory warnings before I upgraded. Not sure if this is relevant or not, but I'm doing most of my testing on an iPhone 3G with iOS 4.2 on it (4.3 is not supported on a 3G).
• Why does the allocations instrument tool live bytes column not match the real memory column in the activity monitor tool ? The activity monitor tool always reports more memory usage.
• According to leaks my app does not leak memory, in the simulator or on an actual iPhone, but when I look at allocations, it seems that as I transition between views and then pop views, the live bytes column does not return to its previous value, which is consistent with leaking memory ? (Yes subviews are released after they are popped)
• My app frequently reports a memory warning on startup, but only when I'm profiling the application with leaks. Does leaks cause extra memory overhead ?
• Perhaps this is a difficult question to answer, but what is a reasonable memory footprint for an iPhone app ? When I'm running leaks, my app will almost certainly be killed due to low memory a few minutes into being run, but allocations in the leaks tool reports I'm using less then 2 MB when the app is terminated.
• Why does the activity monitor instrument have a column for virtual memory ? Everything I've read states that the iPhone does not utilize virtual memory ?
The 4.3 SDK probably does use more memory, but if that's a question you're asking then you're probably on the wrong track, because as a developer that should not factor into how stable your app is.
I would not worry about the discrepancy between what Allocations reports and what Activity Monitor reports. It is also not unusual for the memory footprint to grow, as views are pushed and popped, and not shrink. Another answer on how free(3) works explains this phenomenon in better detail.
A reasonable memory footprint for an iOS app is the lowest amount your app needs in order to function.
iOS does indeed use virtual memory. From Apple's Memory Usage Performance Guidelines / About the Virtual Memory System:
Both Mac OS X and iOS include a fully-integrated virtual memory system that you cannot turn off; it is always on. Both system also provide up to 4 gigabytes of addressable space per 32-bit process.
...
Although Mac OS X supports a backing store, iOS does not. In iPhone applications, read-only data that is already on the disk (such as code pages) is simply removed from memory and reloaded from disk as needed. Writable data is never removed from memory by the operating system. Instead, if the amount of free memory drops below a certain threshold, the system asks the running applications to free up memory voluntarily to make room for new data. Applications that fail to free up enough memory are terminated.
I recommend you read through the whole document, especially Finding Memory Leaks. You can also use the Build-and-Analyze feature, which uses the built-in Clang to statically detect several kinds of bugs, including memory leaks.

Large memory footprint caused by CoreGraphics in Instruments

I'm doing some performance testing in Instruments on the device for an iPhone application that is in development.
I'm seeing that the two largest chunks of memory that are been allocated aren't through any of my custom methods (to my knowledge).
Screenshot 1: http://i.stack.imgur.com/yFFux.png
The background to the application is that it is an application, which uses CoreData to consume a web service and store/display the data. Linked images are then downloaded (async), resized to a smaller size within the app and the new image is then displayed. I originally thought that the images were the problem but testing the app in offline mode without the data or images been downloaded and the large Malloc of 4.5mb still appears.
I'm struggling to identify the source of the memory footprint and ultimately try to reduce/remove it through an AutoRelease pool or another means.
It's really hard to diagnose memory issues from a few screenshots. Your best bet is to learn a bit more about instruments and memory profiling so you can determine for yourself what the problem is. I highly recommend watching the WWDC 2010 session 310 - Advanced Memory Analysis with Instruments. It really helped me to learn where the problems in my app were.

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?

Memory uses limit on iPhone

What is the amount of memory an app can take before getting kicked by iOS?
Does the amount of memory depends on the device version?
I have developed an app which is using 30+ mb and its getting kicked on iPhone 2g. Can it work on iPhone 4 or 3GS?
My experience with the iPhone 3G is that you should try to stay as small as humanly possible--build your data model with ditchability in mind, because you'll need to ditch. 20mb is bumping against the limit. 25 MIGHT be okay if the phone has been rebooted recently. You'll probably never get 30mb.
By contrast... I managed to prompt a memory warning on my iPhone 4 once, but it was due to an infinite loop bug that downloaded the same image file an infinite number of times. In other words, it took something REALLY drastic to crush the 4. Not that you can ignore memory management completely (a leak is still a leak), but for sure you've got some breathing room.
The 3Gs is somewhere between the two. I don't have one to test on, but I'd expect its performace is more 4-like than 3G-like, because while the on-board memory doubled from the 3G, the OS is still taking up the same space, meaning all of the new memory is yours to play with.
All your application's resources on an iPhone 2 should probably stay at less than 20 MB. You can go a little over, but that's it, otherwise the memory warnings will occur. There's only 128 MB of total physical ram for everything - that's the OS as well as your own app.

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.