Skip to content

Instantly share code, notes, and snippets.

@nalitzis
Last active January 13, 2016 07:32
Show Gist options
  • Save nalitzis/5256568eb5d38108b630 to your computer and use it in GitHub Desktop.
Save nalitzis/5256568eb5d38108b630 to your computer and use it in GitHub Desktop.
Available RAM
public static final float BYTES_IN_MB = 1024.0f * 1024.0f;
public static float megabytesFree() {
final Runtime rt = Runtime.getRuntime();
final float bytesUsed = rt.totalMemory();
final float mbUsed = bytesUsed/BYTES_IN_MB;
final float mbFree = megabytesAvailable() - mbUsed;
return mbFree;
}
public static float megabytesAvailable() {
final Runtime rt = Runtime.getRuntime();
final float bytesAvailable = rt.maxMemory();
return bytesAvailable/BYTES_IN_MB;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment