Iβve recently been working on a background uploading feature for an app. One of the key aspects to get right with a feature like that is to correctly handle scenarios where your app is suspended by the system due to RAM constraints or other, similar, reasons. Testing this is easily done by clearing the RAM memory on your device. Unfortunately, this isnβt straightforward. But itβs also not impossible.
Note that opening the task switcher and force closing your app from there is not quite the same as forcing your app to be suspended. Or rather, itβs not the same as forcing your app out of memory.
Luckily, thereβs somewhat of a hidden trick to clear your iOS deviceβs RAM memory, resulting in your app getting suspended just like it would if the device ran out of memory due to something your user is doing.
To force-clear your iOS deviceβs RAM memory, go through the following steps:
- If youβre using a device without a home button, enable Assistive Touch. If your device has a home button you can skip this step. You can enable Assistive Touch by going to Settings β Accessibility β Touch β Enable Assistive Touch. This will make a floating software button appear on your device that can be tapped to access several shortcuts, a virtual home button is one of these shortcuts.
- In a (somewhat) fluid sequence press volume up, volume down, and then hold your deviceβs power button until a screen appears that allows you to power down your device.
- Once that screen appears, tap the assistive touch button and then press and hold the virtual home button until youβre prompted to unlock your device. Youβve successfully wiped your deviceβs RAM memory.
Being able to simulate situations where your app goes out of memory is incredibly useful when youβre working on features that rely on your app being resumed in the background even when itβs out of memory. Background uploads and downloads are just some examples of when this trick is useful.
My favorite part of using this approach to debug my apps going out of memory is that I can do it completely detached from Xcode, and I can even ask other people like a Q&A department to test with this method to ensure everything works as expected.
Top comments (0)