Out of memory error when restarting app (Android)

♀尐吖头ヾ 提交于 2019-12-05 15:22:00

If I recall correctly from the Android API: Pressing the back button does not necessarily mean onDestroy(). The Android OS takes care of garbarge collection for you and calls onDestroy() when it feels like it needs to (for example, when you have launched more apps after pressing back button).

However, there are some ROMS that allow you to "kill" the app by long-pressing the back button.

Can you try unloading the textures from onStop() and report back??

EDIT: Did not see Shark's reply. OnPause() also works --same concept... in fact onPause() is always called before OnStop() so it may be a better solution.

The Garbage Collector doesn't free immediately unused object memory, so if you try to reload new bitmaps after a short, there is no free memory to use for that.

Maybe you should use WeakReference: JVM must free WeakReference objects before throwing an OutOfMemoryException. An example could be found here: http://developer.android.com/training/displaying-bitmaps/display-bitmap.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!