android finish() method doesn’t clear app from memory
original source: https://stackoverflow.com/questions/1977246/android-finish-method-doesnt-clear-app-from-memory
Best way is firstly use finish()
and after that use System.exit(0)
to clear static variables. It will give you some free space.
A lot of applications leave working processes and variables what makes me angry. After 30 minutes of using memory is full and i have to run Task Manager – Lvl 2 clear memory
Its not true that is cousing problems i’ve tried it for over 3 years in my apps. Never get crashed or restart after using Exit()
ImageView를 사용하여 image를 display하는 activity를 여러개 생성하는 경우 out of memory 에러에 맞닥뜨리게 되었다. 그래서 인텐트obj.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)를 사용하면 activity가 생성되더라도 activity stack에서 사라지게 되므로 memory가 바로 확보될줄 알았으나 android studio monitor를 통해 memory 상황을 보니 변화가 없었다. 그래서 onPause() 순간 즉 activity가 화면에서 사라지는 순간 finish()를 통해 activity를 바로 끝내게 했다. 그렇지만 memory는 바로 확보되지 않았다. android os시스템이 memory 회수가 필요하다고 생각되는 순간 확보 되었다. 그래서 위 설명과 같이 System.exit(0)을 사용하니 바로 확보되었다 그러나 잠깐이 화면 정지와 블랙 화면이 나오게 되는 단점이 있다.