Results 1 to 1 of 1
Interacting with the Java Garbage Collector
Java does not have an explicit way to guarantee disposal of unwanted objects. But The Runtime class allows you to make some related requests from the garbage collector:
public void gc()
Asks the virtual machine to expend effort toward recycling unused objects so that their memory can be reused.
public void runFinalization()
Asks the virtual machine to expend effort running the finalizers of objects that it has found to be unreachable but have not yet had their finalizers run.
public long freeMemory()
Returns an estimate of free bytes in system memory.
public long totalMemory()
Returns the total bytes in system memory.
public long maxMemory()
Returns the maximum amount of memory, in bytes, that the virtual machine will ever attempt to use. If there is no limit, Long.MAX_VALUE is returned. There is no method to set the maximum; a virtual machine will typically have a command-line or other configuration option to set the maximum.
To invoke these methods you need to obtain a reference to the current Runtime object via the static method Runtime.getRuntime.