I can not understand this statement from Activity.onStop():
When your activity receives a call to the onStop() method, it's no longer visible and should release almost all resources that aren't needed while the user is not using it. Once your activity is stopped, the system might destroy the instance if it needs to recover system memory. In extreme cases, the system might simply kill your app process without calling the activity's final onDestroy() callback, so it's important you use onStop() to release resources that might leak memory.
Specifically this part:
In extreme cases, the system might simply kill your app process without calling the activity's final onDestroy() callback, so it's important you use onStop() to release resources that might leak memory
If the process is killed how can we get a memory leak if we don’t have release code in onStop
? On app kill all resources are cleaned right?
You can't. The Android documentation gots issues, yo.
Well, your process is terminated, which eliminates your RAM and threads. What you need to do is arrange to clean up anything that isn't tied to your RAM and threads. For example, if the user has entered data into the app that you want to keep and have not persisted yet,
onStop()
is a candidate time to consider forking the thread to save that stuff to disk.If process is killed. All associated memory content will be removed from the system so killing the process will not leak memory.