Skip to content

Instantly share code, notes, and snippets.

@samma835
Created April 27, 2013 07:17
Show Gist options
  • Save samma835/5472190 to your computer and use it in GitHub Desktop.
Save samma835/5472190 to your computer and use it in GitHub Desktop.
function to log the memory status.
private void logMemory(String callingFunction)
{
long max = Runtime.getRuntime().maxMemory() / 1024;
if (debugJavaMemory)
{
long used = Runtime.getRuntime().totalMemory() / 1024;
long available = max - used;
long change = available - availableJavaMemoryOld;
if (availableJavaMemoryOld != 0)
Log.i(TAG_MEMORY, "jMEM M:" + max + ", U:" + used + ", A:" + available + ", C:" + change + ", " + callingFunction);
availableJavaMemoryOld = available;
}
else if (debugNativeMemory)
{
long used = Debug.getNativeHeapAllocatedSize() / 1024;
long available = max - used;
long change = available - availableNativeMemoryOld;
if (availableNativeMemoryOld != 0)
Log.i(TAG_MEMORY, "nMEM M:" + max + ", U:" + used + ", A:" + available + ", C:" + change + ", " + callingFunction);
availableNativeMemoryOld = available;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment