Runtime
class in Java?The Runtime
class has methods that interface and interact with the environment in which the application is run.
freeMemory()
methodThe freeMemory()
method of the Runtime
class is used to retrieve the free memory currently available to the Java Virtual Machine (JVM) for future objects. The value returned by this method is in bytes.
public native long freeMemory()
This method returns the free memory available to JVM.
public class Main { public static void main(String[] args){ Runtime currentRuntime = Runtime.getRuntime(); System.out.println("Runtime.freeMemory() = " + currentRuntime.freeMemory() + " bytes"); } }
getRuntime()
method of the Runtime
class.freeMemory()
method on the current runtime retrieved in line 4.RELATED TAGS
CONTRIBUTOR
View all Courses