2017-08-02 8 views
3

私のアプリのヒープメモリサイズのチェックが必要です。私はAndroid上で私のアプリヒープメモリサイズチェックにandroid:largeHeap="true"アンドロイドで私のアプリのヒープメモリサイズをチェックするには?

方法を使用

拳?

+0

おそらく重複した質問です。 https://stackoverflow.com/questions/2630158/detect-application-heap-size-in-android – Raheel

+0

非常にユニークなアプリを持っていない限り、largeHeap = trueを設定しないでください。必要と思われる場合は、アプリの動作を見て、メモリを少なくしてください。 –

答えて

0

メモリの容量は、Androidのバージョンとデバイスモデルによって異なります。

public static void logHeap() { 
     Double allocated = new Double(Debug.getNativeHeapAllocatedSize())/new Double((1024*1024)); 
     Double available = new Double(Debug.getNativeHeapSize())/(1024*1024.0); 
     Double free = new Double(Debug.getNativeHeapFreeSize())/(1024*1024.0); 
     DecimalFormat df = new DecimalFormat(); 
     df.setMaximumFractionDigits(2); 
     df.setMinimumFractionDigits(2); 

     Log.d("tag", "debug. ===Heap====Heap======Heap====Heap====Heap====="); 
     Log.d("tag", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free)"); 
     Log.d("tag", "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory()/(1024*1024.0))) + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory()/(1024*1024.0)))+ "MB (" + df.format(new Double(Runtime.getRuntime().freeMemory()/(1024*1024.0))) +"MB free)"); 
    } 
+0

https://gist.github.com/bepcyc/1704273 –

関連する問題