I've an app on the App Store that monitor the system status. My users require a Free Memory button to clean the RAM. I know that iOS manages the memory as OS X, so the inactive memory, practically, is free memory, right? Simply the inactive memory helps to run quickly some recent applications. In iOS how can I do a clean for the memory? I see a lot of apps do it, but how?
-
I do not believe that this is possible on iOS. – Ahan Malhotra Aug 31 '13 at 16:42
2 Answers
The general way it works is to allocate large chunks of memory, forcing other apps to give up their non-essential memory and force the closing of other apps. They get as much memory internally as they can before getting their own memory warning, then they free everything.

- 33,113
- 21
- 131
- 183
-
Good way. But, how can I do it with code? Practically, using ARC, how can I do? – Andrea Mario Lufino Aug 31 '13 at 22:30
-
SO isn't a "give me code" site, rather a site to ask specific questions about problems, or to get help about specific aspects of code you have already written. I would suggest reading up on malloc and free – coneybeare Sep 01 '13 at 13:43
-
You can do as the user answer says and allocate memory in a loop using malloc
and memset
until you get a didReceiveMemoryWarning
. This would get memory until your app is about to be killed by iOS, so should be enough.
This project illustrates how to do it. It's a pretty handy app, by the way.
There's a caveat, in my experience iOS doesn't allowing all theoretically possible memory to be given to an app, even when all the other apps are inactive. This SO answer uses the project I mentioned in many devices and it evidences that iOS will give you up to a certain amount of memory and no more, no matter what's being run in the device.