Android开发实践:检测App的内存占用和泄漏html
http://www.linuxidc.com/Linux/2014-03/97563.htm
java
官方文档对于内存管理linux
http://developer.android.com/intl/zh-cn/training/articles/memory.html
android
http://blog.csdn.net/hknock/article/details/47322005 (中文翻译)
web
Android代码内存优化建议-Android资源篇面试
http://blog.csdn.net/hknock/article/details/47322005
segmentfault
https://cloud.tencent.com/developer/article/1070616 (一招内存优化)api
http://blog.csdn.net/vshuang/article/details/39647167
缓存
ANDROID 探究oom内幕网络
http://blog.csdn.net/chengyingzhilian/article/details/8662849
Android DiskLruCache缓存彻底解析
http://blog.csdn.net/lwyygydx/article/details/40401211
http://blog.csdn.net/yangyuankp/article/details/7651251
http://java-mzd.iteye.com/blog/848635
http://segmentfault.com/a/1190000002579346
如何制造OOM?
不要用while循环来制造oom,不易于控制,容易崩溃了,onTrimMemory方法也就没有回调了。看我下面的有个make(int count)方法,若是onTrimMemory没有回调,就多调用几回。
package com.mh.webappStart.util; import android.graphics.BitmapFactory; import android.os.Environment; import android.os.SystemClock; import com.gen.mh.webapps.utils.Logger; import com.gen.mh.webapps.WebViewFragment; import com.gen.mh.webapps.utils.Logger; import com.mh.webappStart.WebApplication; import java.io.File; public class OOMMaker { private static final String TAG = "OOMMaker"; private static boolean isStop = false; public static void make(){ isStop = false; while(isStop == false){ Logger.e(TAG, "onTrimMemory test " ); new Thread(){ @Override public void run() { WebViewFragment webViewFragment1 = new WebViewFragment(); WebViewFragment webViewFragment2 = new WebViewFragment(); WebViewFragment webViewFragment3 = new WebViewFragment(); WebViewFragment webViewFragment4 = new WebViewFragment(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = false; options.inSampleSize = 1; // 原图的五分之一,设置为2则为二分之一 BitmapFactory.decodeFile(WebApplication.getInstance().getApplication().getFilesDir() + File.separator + "app/api_plugin/images" + File.separator + "oom_test.jpg", options); } }.start(); } Logger.e("stop make oom ..."); } public static void make(int count){ for (int i = 0; i < count; i++) { Logger.e(TAG, "onTrimMemory test " + i ); new Thread(){ @Override public void run() { WebViewFragment webViewFragment1 = new WebViewFragment(); WebViewFragment webViewFragment2 = new WebViewFragment(); WebViewFragment webViewFragment3 = new WebViewFragment(); WebViewFragment webViewFragment4 = new WebViewFragment(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = false; options.inSampleSize = 1; // 原图的五分之一,设置为2则为二分之一 BitmapFactory.decodeFile(WebApplication.getInstance().getApplication().getFilesDir() + File.separator + "app/api_plugin/images" + File.separator + "oom_test.jpg", options); } }.start(); } Logger.e("stop make oom ..."); } public static void stop(){ Logger.e("stop make oom2 ..."); isStop = true; } }
前些日子,一位面试官(乔丽云,大约30来岁,个子不是很高),我从她那里确实领会了一些东西:
假若有这样一个需求,判断一个文件的格式
通常的人会将格式所有存入HashMap当中,而后去遍历,而后问我有没有什么优化的方法,就是不写
入到内存当中?
答案:用if else或switch来用语法来判断,这样是节省了内存,可是在性能上可能上会有必定的代价。
在Activity退出,注销登陆时,若是还有网络请求在运行,应该怎么取消?
Volley库能够作到
对于一些图片库,在下载完图片时,若是任务在进行,而界面退出了,应该怎么取消?图片库作了
什么处理?
DiskLruCache详解
http://blog.csdn.net/lwyygydx/article/details/40401211