memory of drawables, is it better to have resources inside APK, outside APK or is it the same for memory?

不问归期 提交于 2019-12-08 04:57:11

问题


I have an application that draws a lot of graphics and change them. Since I have many graphics, I thought of having the images outside the APK, downloaded from the internet as needed, and saved on the files application folder.

But I started to get outOfMemory exceptions.

The question is: Does android handle memory different if I load a graphic from APK than if I load it from 'disk'?

code using APK:

topView.setBackgroundResource(R.drawable.bg);

code if image is outside APK:

Drawable d = Drawable.createFromPath(pathName); topView.setBackgroundDrawable(d);

Thanks

Daniel


回答1:


No, internally they are handled the same. Most likely, you're leaking the images, or not cleaning them up as quickly as you could. Try calling Bitmap.recycle(); once you're done with an image, to force Android to clean it up.




回答2:


At runtime, the memory footprint you're seeing should be about the same no matter which way you load it. Android will use a utility to byte-align resources internal to the apk which should improve loading times.



来源:https://stackoverflow.com/questions/2005916/memory-of-drawables-is-it-better-to-have-resources-inside-apk-outside-apk-or-i

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