iphone 3gs memory warning calling query - iphone

hi i just want to know this: When will iphone 3gs and iphone 4 send out memory warnings
i mean after how much memory our app uses does the both devices send warnings?
Thanks

You don't know when it will fire. You don't know how much memory is being used by other apps running in the background, Safari keeping webpages, etc. Pandora might be streaming in the background and it might be using a significant amount of memory. Don't count on any single amount of memory. Load lazily, and release uneeded allocations in didRecieveMemoryWarning.
If your app requires a lot of memory, some game developers tell their users to restart the device before playing to ensure the most memory for the app, and best performance.

It is not strictly defined but Apple suggests you don't use more than 24MB of graphical memory as overuse of graphical memory is typically why an application receives a low memory warning.
The only good way to manage critical low memory situations on the iPhone is to implement the didReceiveLowMemoryWarning delegate methods and release as much memory as possible at that point. This means for instance:
All non-visible images currently loaded in memory
All view controllers and their subviews if not in use
This can of course be done safely provided your application is able to reload that information at a later stage. didReceiveLowMemoryWarning is however a last resort situation for your application.
To avoid getting to that point it is recommended to only load resources lazily i.e. when and only when you need them, and release them when they are no longer needed (for instance implementing viewDidUnload on all your controllers).

Related

Why bother to use Memory warning event methods?

If my app uses less than 10MB do I have to bother to use those methods? I know that they are for caching low memory situations but this might occur only if you do not tested you app before releasing it. If you have tested your app, the app does not have leaks, have a small memory footprint, then why should anyone bother to use memory warning methods?
Your app is probably not the only thing running on the device. Other apps and processes are also taking up memory, and in some situations they may need it more than you. It's always a good idea to respond to memory warnings by releasing cached data that can easily be loaded again. That way the operating system has control over the memory usage, and it won't have to terminate your app.

How do keep memory usage and size of application down (iPhone)?

I am currently working on a personal iPhone project that is very audio and graphic-intense and I have therefore been quite conscious of how much of a footprint my application has (in terms of both memory usage while active and/or in 'multi-tasking mode' and how much the size of application is) as Apple sub-consciously gets into my mind and has drilled in the fact the iPhone has limited memory and capacity - and I was curious if any of you guys had any solutions that could help me keep down the usage of my application - I've open up Instruments and configured some aspects although this primarily appeals to me as a performance utility). I have also been testing on my device as I cannot stand the simulator...
As long as you are properly releasing objects that aren't being used, you should be fine. If you are loading large images and audio files, then your app will require more memory to handle those, so alloc/release those as they are needed.
Also, debugging memory issues on the Simulator just wont work, so don't rely on it for testing memory issues.

Creating low memory conditions on IPad device

I want to test the behaviour of an app repeatedly at low memory conditions. I want these low memory states to be reproducable.So runnly lots of websites in the background is not enough.
I've read the similar post on
How to test memory low condition on real iphone/ipad device (not simulator)?
Has anyone created a background app with this functionality?
Saving the memory state to file would be also useful.
The problem is, iOS will kill the background app before it notifies you that there is not enough memory. So you have to consume the memory within you app.
A way would be to repeatedly allocate memory over a amount of time (allocating it all at once will force iOS to kill your app afair).

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.

If my application doesn't use a lot of memory, can I ignore viewDidUnload:?

My iPhone app generally uses under 5MB of living memory and even in the most extreme conditions stays under 8MB. The iPhone 2G has 128MB of RAM and from what I've read an app should only expect to have 20-30MB to use.
Given that I never expect to get anywhere near the memory limit, do I need to care about memory warnings and setting objects to nil in viewDidUnload:? The only way I see my app getting memory warnings is if something else on the phone is screwing with the memory, in which case the entire phone would be acting silly. I built my app without ever using viewDidUnload:, so there's more than a hundred classes that I'd need to inspect and add code to if I did need to implement it.
Yes, please free all memory that you don't use!
Behaviours like this are one of the reasons Apple doesn't allow multiple Apps to run at the same time. Now imagine sometimes they will and all programs would be written like this...