Finding app heap availability
VMRuntime was a great class provided in Android SDK to find and alter information about the VM used by your application.
http://developer.android.com/sdk/api_diff/5/changes/dalvik.system.VMRuntime.html
However, this has been deprecated since version 5 mentioning this was only intended for Internal usage and not for public usage. That;s sad since we cannot find useful functions elsewhere.
If you do want to find memory consumption of the system, you can use:
ActivityManager actvityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
ActivityManager.MemoryInfo mInfo = new ActivityManager.MemoryInfo ();
actvityManager.getMemoryInfo( mInfo );
Log.i(TAG, " minfo.availMem " + mInfo.availMem);
Log.i(TAG, " minfo.lowMemory " + mInfo.lowMemory);
Log.i(TAG, " minfo.threshold " + mInfo.threshold);
If you are looking for information for your app, you can use the java provided Runtime methods:
Log.i("AvailableHeapMemory", " Runtime.getRuntime().freeMemory() "
+ Runtime.getRuntime().freeMemory());
Log.i("AvailableHeapMemory", " Runtime.getRuntime().maxMemory() "
+ Runtime.getRuntime().maxMemory());
Log.i("AvailableHeapMemory", " Runtime.getRuntime().totalMemory() "
+ Runtime.getRuntime().totalMemory());
Comments
Post a Comment