Last active
January 13, 2016 07:32
-
-
Save nalitzis/5256568eb5d38108b630 to your computer and use it in GitHub Desktop.
Available RAM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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