Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we get a memory leak even if the app is killed?

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?

like image 309
Jim Avatar asked Apr 28 '15 14:04

Jim


1 Answers

If the process is killed how can we get a memory leak if we don’t have release code in onStop?

You can't. The Android documentation gots issues, yo.

On app kill all resources are cleaned right?

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.

like image 184
CommonsWare Avatar answered Sep 20 '22 13:09

CommonsWare