available RAM iPhone app - iphone

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

Related

iPhone and iPad App Real and Virtual Memory usage

I've been trying to keep my iOS Apps memory footprint nice and low, however, I'm not really sure what a good threshold is for either real or virtual memory is iOS.
At the moment a very simple app is using 12MB real memory and 70MB virtual memory but this is going to increase as my app becomes more complex.
My question is, what are the real and virtual memory levels that I should try to keep below to avoid getting memory warnings?
I realise that this is not an exact science as there are other factors like the memory footprint of other apps on the system but a rough answer would be welcomed.
This is indeed not at all an exact science. In my experience it's at least as important to release enough memory immediately when receiving an OS request to do so as it is to keep memory low.
That being said, as long as I keep my apps under ~80 MB real memory on an iPad I typically don't get any warnings (for refernce, iPad 1 has 256MB). (keep in mind, this is the full memory used, including screen buffers etc. allocated by the OS for your app, not just what you allocated yourself)

Can my iPad app cause the device to reboot?

I have an iPad app that has a process for downloading lots of map files (a couple of gigs of data and 10s of thousands of files).
In my most recent test release, the device will sometimes reboot during the download process, (downloads can take a couple of hours).
When the app reboots, it does not leave a crash report. We have observed this behavior on both an iPad 1 and an iPad 2 running 4.3.3.
The only thing I can think of is we increased the max concurrent threads from 4 to 20 for doing these downloads.
Completely exhausting the system memory triggers a hard reboot of the device. This used to be more common in iPhone OS 2.0, running on the limited hardware of the initial iPhones and iPod touches. In recent OS versions, Apple has more rigidly enforced the hard kill of your application when it exceeds its memory ceiling, so it's become much harder to do this. Also, the devices have much more memory than they used to.
One way that you can sometimes do this is by loading many large textures or other graphical components that may not be immediately identified as memory used by your application. I've been able to cause a system reboot when loading a pile of data onto the GPU in a tight loop. You may be encountering something similar here.
I doubt that this is related to the number of active threads you have going, although they probably make it easier for you to dump a mess of data into memory before the system can kill your application.
As an aside, rather than having piles of threads, which consume resources, have you looked at using GCD or a queue-based framework like ASIHTTPRequest? These might be more efficient for your application, yet still provide the concurrency you need.
Your app is crashing most likely due to memory management. Since you are downloading several GB's of data, maybe you are running out of disk space? I am not sure why it would take your device several hours to reboot.
Try posting some code.
Have you debugged in Instruments? This will show you if allocations are rising and filling memory. If you are attempting to load these GBs into memory, then of course your going to experience a crash.
Also, have you looked at dispatch_apply instead of threads? GCD automatically distributes and increases/reduces the threads it uses based on load. This way you don't have to manage this yourself. It might be worth a shot.

Is Spiky Memory "Healthy" for App?

I've recently been developing an app that processes a large amount of data very frequently (~15 times a minute). To do so, I allocated a large chunk of memory, then freed it for each batch of data.
Here's a screen of my Memory Allocations from Instruments:
The Memory usage oscillates from about 3MB to about 30MB pretty quickly. I was just wondering, is this "healthy," per se for the iPhone.
Is it risky to allocate and free so much memory so quickly? Is it unsustainable, or just bad practice?
Thanks!
It is neither risky nor necessarily bad practice. Allocating and freeing memory takes time, so doing it very frequently vs. doing it once and re-using the allocated memory is a trade-off between memory usage efficiency (using the lowest amount of memory at every single moment) and performance.
If the performance of your app doesn't suffer at the moment, you have probably made the correct choice regarding this tradeoff for your app.
Generally speaking, using 30 MB of memory is quite a large amount for older devices (iPhone 3G and older). You cannot be sure that your app has that much memory available so be prepared to received memory warnings. If your app cannot reduce its memory usage when it receives a memory warning, the OS might kill it.
My primary worry in these situations would be fragmentation. If the chunks are all the same size though, you should be fine (and looking at your graph, the peaks appear to be completely level, so I think that's the case).
You will be paying allocation costs, but as Ole says, if your app is performing well enough already, there's not much point in trying to optimize that.
It depends, if the user has an iPhone 4 or iPhone 3GS it should be do-able but on the iPhone 3G it will result in a memory warning very quickly.
iPhone 4 has 256mb of RAM for the apps ( 512 mb in total )
iPhone 3GS has 128mb for the apps, and 256 in total
the iphone 3g only has 128mb and 64mb for the apps.. usually having around 40mb free when no apps are running.
As apple says you should only allocate the memory you really need, and try to not use autorelease too much, because autorelease gives us an object being allocated while we
don't really need it anymore
If the performance isn't too bad, I would try using less memory and allocating more when you really need it.

my iPhone software is so slow!

I ported one of my mac applications to the iphone. WOW!!! is it slow! At first I started thinking maybe I was doing a lot of disk access. But as I started looking I realized I simply do an offset read of a binary file. I only read in about 512 bytes of data. I also have an array that is huge. Maybe 2MB. But why would that be slow? It is perminatly located in memory.
I would love to hear some ideas from you all!
When you have major performance problems, the tool to pull out first is Instruments. Start with "Run With Performance Tool > CPU Sampler" and get a feel for where your app is spending its time. After that, check Object Allocations to see if you're hitting memory harder than you should. iPhone is a resource-constrained environment compared to the Mac. Things that you think of as fast can dramatically impact performance on iPhone. Disk access is much more expensive. Even allocating memory can be a significant impact (welcome to the world that server developers deal with every day). You only have one core, so things you stuck off on a background thread now compete with your main thread. It's a different world.
It's hard to debug the application over Stackoverflow, but there are many reasons why the iPhone app runs much slower: Your mac applications run on probably the latest CPUs with tons of memory, as for the iPhone it's very limited (3GS is rumored to have 600MHz CPU with 256MB RAM). Also, Mac applications are a bit more forgiving when it comes to memory usage; as for the iPhone it's important that only create the objects you need when you need them and release them when you no longer use them. Delaying object de-allocation results in some slowdown as well.
I recommend using Instruments performance profiling tool, that is bundled with XCode and the Developer tools. It'll give good tips on what the bottlenecks are.

What's the maximum memory footprint in MB for an typical iPhone app?

I know this is a subjective question. As far as I know, there are somewhat about 25 MB available for the app, but it depends on what else is going on. Currently playing music, a current phone call or what ever might drop that amount of memory down a lot. I don't know.
Just tell us what you think, or what you have experienced. My app currently consumes about 15 MB at a time, mostly lots of images loaded into views for animation. I have encountered no problems with this. But is there some "border" that can be drawn, to make a simple-to-follow rule like "do not consume more than x MB of memory at any given time", where x stands for the max amount?
This value highly varies per device and per user. For example, I restart my phone every few days, freeing up lost memory claimed by Apple and 3rd party leaks. My mother, has not restarted her phone ever on her own. EVER. She has tons of trouble with apps, gives me a call and I tell her to restart the phone to increase the ram. She does and the apps dont crash anymore.
Moral of the story is: Never plan on having available memory. You should always keep your memory down to the bare minimum you need at any given time.
You can use Instruments and launch some apps and find out for yourself.
Recently I found this awesome tool to find what is the maximum memory capacity of any iOS device.
We can also find at which memory level we received the Low Memory warning.
here is the link: https://github.com/Split82/iOSMemoryBudgetTest