1

Is there a way to kill background apps?

I have an app that I am working on that records a sound and then plots it out on a scroll view the problem I had with it is it crashes if the recording is too long because it runs out of memory trying to plot it. My fix to this is to monitor the amount of free memory and predict how much memory usage plotting will take and stop the recording just before there is not enough. The problem with that is the more apps I have running in the background the sooner it stops recording instead of killing background apps to make space the way that ios does before a didRecieveMemoryWarning. To restate my Question how can I kill these background apps? Will Apple frown upon this?

Filip Radelic
  • 26,607
  • 8
  • 71
  • 97
Daniel
  • 493
  • 1
  • 5
  • 13
  • 4
    I think your design is broken if you need to ask this question. You should decouple your view from your model, and give the former sufficient intelligence to deal with low memory warnings. UITableView does essentially the same thing for those views it can display. – Tommy Aug 11 '11 at 04:27

3 Answers3

5

You want to kill other background apps programmatically from your foreground app? I suspect Apple would frown on that.

In theory you can get their process id's from sysctl and send them a SIGKILL to terminate them, but iOS won't let you get info about other processes unless you are root (which means jailbreaking).

Community
  • 1
  • 1
progrmr
  • 75,956
  • 16
  • 112
  • 147
  • well thats a shame I was hoping it would be something as simple as calling a system routine. well I guess I will have to make it plot as it records I guess that will be even better looking. Thank you. – Daniel Aug 11 '11 at 04:30
  • you can also stop recording the second time you get a memory warning. free up what you can on the first warning, but stop on the 2nd warning (or maybe even try waiting for the 3rd warning) – progrmr Aug 11 '11 at 04:51
  • You can get as far as getting the process ID legally, look at http://www.macstories.net/reviews/appswitch-cool-process-management-app-for-iphone/ I think they are using a combination of URL scheme database and ASL logs. – Jano Aug 11 '11 at 07:33
1

iOS will start terminating unused background apps itself at the same time when it starts sending you memory warnings. But you shouldn't be getting memory warnings at all, try to fix your memory management instead.

Filip Radelic
  • 26,607
  • 8
  • 71
  • 97
1

Killing background apps do not solve your problem. Even all other apps are killed, your apps will still crash after a while.

Consider use a small buffer to store those data and write them regularly to storage. When user need to scroll back and read older records, read them back from storage. By limiting the window size, the app will only use certain amount of memory.

siuying
  • 1,449
  • 12
  • 15