开发者

Tips for saving memory when coding under android?

Im currently developing a software under android and im getting quite quickly some OutOfMemoryException.... I did modified some part of my code to use more static variables instead of making new allocation with the "new" operator but is there any things else to do ? or any ot开发者_运维问答her tips ? Any advices would be welcome.

Thanks.


You can find a lot of tips here: http://developer.android.com/guide/practices/design/performance.html

Especially look at the Avoid Creating Objects topic.


You can also watch some Google I/O conferences, like the ones about writing non-janky apps or how to make fast and efficient apps from 2009.


If you have some resources that can be reloaded onto memory anytime, consider using WeakReferences. The objects inside them will be cleared just before the (Java) VM throws OutOfMemoryException, so there will be some more memory available.


You may be accessing too many resources (such as images) before garbage collector can handle/recycle them. If you're accessing particularly large images, then use BitmapFactory to scale them down, as seen answered on SO. (Of course, for this you would see something like "bitmap size exceeds vm budget" in your logcat too.) Any more details on the error?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜