Android: How much memory does my application use?

advertisements

Memory seems to be a big topic and I cant find the specific answer. I've got the answers on how much is available in the heap and I know how much should I use. I need the answer how to code to programatically determine how much memory is my app using of the heap? And how much total memory am I using?


This works:

  Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
  Debug.getMemoryInfo(memoryInfo);

  String memMessage = String.format("App Memory: Pss=%.2f MB\nPrivate=%.2f MB\nShared=%.2f MB",
  memoryInfo.getTotalPss() / 1024.0,
  memoryInfo.getTotalPrivateDirty() / 1024.0,
  memoryInfo.getTotalSharedDirty() / 1024.0);

  Toast.makeText(this,memMessage,Toast.LENGTH_LONG).show();
  Log.i("log_tag", memMessage);