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

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?

Related

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.

available RAM iPhone app

how do i increase the available memory (more concrete: the part of the RAM) that can be used by my app?
i am not referring to the space available on the harddisk of an iphone, but to the RAM.
does anyone know if there's a way to use the whole free part of the RAM for my app only?
i have to clear this up a bit, sorry if it was too vague:
i had to think of the java heap size, which can be increased by adding a parameter to the startup command of the java programming.
as i don't know, but at the moment suppose on the iphone something similar happens (every app has just xxMB RAM for execution) this value might be adjustable, so that i can use the whole remaining RAM for my app.
which pretty much is what i need for this special app (non-app-store-publication; file-sizes between 50MB and several 100MB)
How do i increase the available memory?
Short answer: you don't.
Memory is managed by the kernel.
Your application process can't control this.
You can't explicitly control this - this is managed by iOS.
You can't do that. Try reducing your memory usage instead of looking for ways to remove well needed limits.
Store your data instead and read from it when needed.
I don't know for sure if you can configure RAM allocated for your app. I think that is taken care of by the iOS kernel
It's unlikely (read: not going to work) that you will be able to allocate anything more than a few Mb in your application at once.
Not planning on publishing your app to the App Store won't change this. Apple don't officially acknowledge the amount of memory in iOS devices. But its known that devices have between 128Mb and 512Mb of physical RAM.
With the kernel, essential applications (Phone app, etc), background processes, etc, you won't have anything like that available to your application. Careful analysis in instruments would suggest that you'll generally start getting memory warnings when you've allocated around 22Mb of RAM in your application.
A change made in iOS 5 makes the watchdog process much more aggressive with killing applications after you get a memory warning. If you get a memory warning on iOS5 you have to reduce your memory usage or you will get jettisoned by the OS.
If you want to proceed, you will have to figure out how to reduce the amount of memory your datasets require. Its unlikely that all of the 100Mb file needs to be in memory at once. iOS devices have "relatively" fast CPU's and storage, you'll have to architect your application to read and write to storage in chunks and work on smaller subsets of your data.
Some related Stackoverflow questions and links:
Monitor memory usage in an iphone app?
How much memory can an iPhone app use?
10 iPhone Memory Management Tips

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.

How do I free RAM on the iPhone using Xcode and the iOS SDK?

I am having some trouble finding out how to free RAM on the iPhone using Xcode and the iOS SDK. If anyone could give me a hand doing this, that would be great.
Generally one implements behaviour to free things like cached data, in the -didReceiveMemoryWarning method. Then, when the OS sends a memory warning to your application, that method will be called.
the simulator has a control to simulate a low memory warning
If this is for your own use (not for the App store), and you wish to push other apps out of memory, then use a repeating NSTimer to continue to try and allocate (malloc) large and random page sized memory blocks, say 30 times a second for several seconds, and/or until you can't allocate any more, all the while mostly ignoring memory warnings.
Then free all these allocations at once... if your app is the one left running by the OS.

How much memory can an iPhone app use?

Can anyone link me to a page that describes memory allocations for iPhone apps.
I have heard that you are limited to a sandbox of ~20 megs, depending on the state of the phone, but I can't find the source for this.
It depends on the device you're using. I've found that with an iPhone 3G, when the total memory your app is using goes over 10-14MB, it's vulnerable to crashing. When it hits 20MB, it will crash for sure.
As far as I know, Apple doesn't give any hard figures for the memory that you can use. It's always changing so it's hard to pin down. They recommend that you rely on memory warnings and respond to them appropriately.
iPhone 3GS has a much higher amount of memory available to apps (I've heard that it's around 4 times). Although the iPhone 3GS only has double the memory of the iPhone 3G, a lot of that memory is taken up by the OS. There's very little left for apps to run in. That's why the 3GS will allow apps to use so much more memory.
Also, there can be a lot of memory already in use by the OS. One example is when safari is keeping a lot of tabs open. This is why lots of games recommend that you restart the device if it crashes a lot.
When you're programming, keep an eye on the increase of memory (due to not properly deallocating objects) and the peak memory. This problem is more about real-world testing (on as many devices as possible) and good programming practices.
Here's an article to ready more about how to deal with memory problems:
http://akosma.com/2009/01/28/10-iphone-memory-management-tips/
This tool finds what is the maximum memory capacity of any iOS device. It also can also find at which memory level you received the Low Memory warning.
here is the link: https://github.com/Split82/iOSMemoryBudgetTest
It depends on current device state. Some native iPhone applications can run in background and waste device resources(Mail, Safari, Sms, Phone...) So, it's hard to say how much memory u will get...Ideally, your application should stay within 10-12Mb limit to successfully overcome any memory issues.
I believe it's
Memory warnings at 20MB
Application "crashes" at 30MB
I'm fairly certain I saw this in The iPhone Developer's Cookbook: Building Applications with the iPhone SDK by Erica Sadun (amazing book, btw).
Also: Duplicate -> Maximum runtime memory available in iPhone and iPod?.