2

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Andrea Mario Lufino
  • 7,921
  • 12
  • 47
  • 78

2 Answers2

1

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.

coneybeare
  • 33,113
  • 21
  • 131
  • 183
-1

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.

Community
  • 1
  • 1
Roberto
  • 11,557
  • 16
  • 54
  • 68