Android内存优化总结【整理】
来源:互联网 发布:js中设置css样式 编辑:程序博客网 时间:2024/05/21 14:53
- http://blog.csdn.net/tiantangrenjian/article/details/39182293
- http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0920/3478.html
- http://blog.csdn.net/kifile/article/details/40751665
- http://android.jobbole.com/82248/
- http://blog.csdn.net/tiantangrenjian/article/details/39182293
- http://blog.csdn.net/a396901990/article/details/38904543
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------!
内存占用检测工具:
http://blog.csdn.net/xu_fu/article/details/45678373
AS自带Monitor工具使用:
http://blog.csdn.net/yutao52shi/article/details/50055669
独立 MAT工具使用:
http://www.jianshu.com/p/216b03c22bb8
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------!
原图大小285kb,宽高1354x848
直接加载到内存中,内存暴涨54M
设置ImageView宽高为100px x 100px ,内存没有任何变化,还是54M
使用下面的方法先缩放,再加载。缩放为100,100,结果内存只涨了3M!!! 千差万别啊。。。。。
public Drawable resizeImage(int width, int height) { //获取图片宽高 BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; //不加载bitmap到内存中 BitmapFactory.decodeResource(getResources(), R.drawable.aa, options); int oldWidth = options.outWidth;//原图 宽度 int oldHeight = options.outHeight;//原图 高度 //得到新的缩放比例 int sampleSizeNew = 1; if (oldWidth != 0 && oldHeight != 0 && width != 0 && height != 0) { sampleSizeNew = (oldWidth / width + oldHeight / height) / 2; } //创建新的option BitmapFactory.Options optionsNew = new BitmapFactory.Options(); optionsNew.inJustDecodeBounds = false;//加载bitmap到内存中 optionsNew.inSampleSize = sampleSizeNew;//新的缩放比例 //按照新的option加载图片 return new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.aa, optionsNew)); }
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------!
ctx就是整个Activity的引用。
有两个Activity,A和B。
A跳转到B,B把自己的ctx放到了另外一个类的静态变量,然后返回到A。
那么这个时候,B所有的资源,都不会被释放!因为另外一个类的静态变量,一直对它有一个引用。
我们单例的时候,传入的ctx就是这样的!!!
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------!
java一直会做内存回收的,在内存紧张的时候。
但是,但是!如果对象被引用,有引用关系在,无法回收。那么最后到达 阀值,就OOM了。
这个才是OOM的原因!!!!!!! 有东西无法被回收!!!回收不了!被引用着呢。
- Android内存优化总结【整理】
- Android内存优化总结【整理】
- Android内存优化总结【整理】
- Android内存优化总结【整理】
- Android内存优化总结【整理】
- Android内存优化总结【整理】
- Android内存优化整理
- android 内存优化方式整理
- android 内存优化方式整理
- android 内存优化总结
- Android内存优化总结
- android:内存优化总结
- Android 内存优化总结
- Android 内存优化总结
- Android内存优化总结
- android 内存优化总结
- android内存优化总结
- android内存优化总结
- 8.python学习笔记:python发送邮件
- tar解压文件到指定目录出现Not found in archive
- Qt中QString::toStdString().c_str() 偶尔存在问题
- SHA加密(单向)
- NGUI聊天信息中插入动态表情
- Android内存优化总结【整理】
- ndc iptables ip命令积累ing
- Tomcat下快逸报表中文乱码问题怎么解决
- Http 模拟构造提交
- 面试问题总结(一)
- angular $scope.fun | js obj method
- select,poll,epoll详解
- iOS获取设备唯一标识的八种方法
- float类型在内存中的存储方式