- 使用轻量数据结构
- 少用ENUM:比static变量占用内存多几倍
- 减少bitmap内存占用:预加载宽高(inJustDecodeBounds=true),缩小size(缩小2的inSampleSize次幂),改解码方式(一般不太方便),ARGB_8888一个像素32位,换成其他的,但是图片颜色,清晰度什么的会受影响。
- bitmap:LRUCache
- listview:item view
- recyclerview:view holder
- 避免在onDraw()等频繁执行的方法内创建对象
- stringbuilder/stringbuffer
- 优先用application context代替activity context。
- handler:onDestroy()之前remove掉消息队列中的消息和runnable对象,或者static加weakReference引用外部类。 引用链如下:looper->messagequeue->message->handler->outter class
- listener的注销
- cursor,connection关闭。
- 容器中对象未清理。
- webview