Android內存控制


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


Android 內存管理 &Memory Leak & OOM 分析

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


Java內存分配全面淺析

 http://blog.csdn.net/yangyuankp/article/details/7651251


Java內存分配、管理小結

 http://java-mzd.iteye.com/blog/848635


JVM 的 工做原理,層次結構 以及 GC工做原理

 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來歲,個子不是很高),我從她那裏確實領會了一些東西:

  1. 假若有這樣一個需求,判斷一個文件的格式

    通常的人會將格式所有存入HashMap當中,而後去遍歷,而後問我有沒有什麼優化的方法,就是不寫

    入到內存當中?

    答案:用if else或switch來用語法來判斷,這樣是節省了內存,可是在性能上可能上會有必定的代價。

  2. 在Activity退出,註銷登陸時,若是還有網絡請求在運行,應該怎麼取消?

    Volley庫能夠作到

  3. 對於一些圖片庫,在下載完圖片時,若是任務在進行,而界面退出了,應該怎麼取消?圖片庫作了

    什麼處理?


DiskLruCache詳解

http://blog.csdn.net/lwyygydx/article/details/40401211

相關文章
相關標籤/搜索