Java Reference
In-Depth Information
17.4. Interacting with the Garbage Collector
Although the language has no explicit way to dispose of unwanted ob-
jects, you can directly invoke the garbage collector to look for unused
objects. The Runtime class, together with some convenience methods in
the System class, allows you to invoke the garbage collector, request that
any pending finalizers be run, or query the current memory state:
public void gc()
Asks the virtual machine to expend effort toward recycling un-
used 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 max-
imum; a virtual machine will typically have a command-line or
other configuration option to set the maximum.
 
Search WWH ::




Custom Search