Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
public interface MemoryMXBean
ManagementFactory.getMemoryMXBean()
.
The Java virtual machine uses two types of memory: heap memory and non-heap memory. The heap is the storage location for class and array instances, and is thus the main source of memory associated with running Java programs. The heap is created when the virtual machine is started, and is periodically scanned by the garbage collector(s), in order to reclaim memory which is no longer used (e.g. because an object reference has gone out of scope).
Non-heap memory is used by the virtual machine in order to perform its duties. Thus, it mainly acts as the storage location for structures created as a result of parsing Java bytecode, such as the constant pool and constructor/method declarations. When a Just-In-Time (JIT) compiler is in operation, this will use non-heap memory to store compiled bytecode.
Both types of memory may be non-contiguous. During the lifetime of the virtual machine, the size of both may either change (either expanding or contracting) or stay the same.
Implementations of this interface also conform to the
NotificationEmitter
interface,
and supply two notifications reflecting memory usage.
These notifications occur when a usage threshold is
exceeded; for more details of these, see the documentation
of MemoryPoolMXBean
. If threshold monitoring
is supported, then a notification will be emitted each time
the threshold is crossed. Another notification will not
be emitted unless the usage level has dropped below the
threshold again in the meantime.
The emitted notifications are instances of
Notification
, with a type of
either
MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED
or
MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED
(depending on whether the notification refers to the general
usage threshold or the garbage collection threshold) and an instance
of MemoryNotificationInfo
contained
in the user data section. This is wrapped inside an instance
of CompositeData
, as explained
in the documentation for
MemoryNotificationInfo
.
Method Summary | |
void |
|
MemoryUsage |
|
MemoryUsage |
|
int |
|
boolean |
|
void |
|
public void gc()
Instigates a garbage collection cycle. The virtual machine's garbage collector should make the best attempt it can at reclaiming unused memory. This is equivalent to invokingjava.lang.System.gc()
.
- See Also:
System.gc()
public MemoryUsage getHeapMemoryUsage()
Returns aMemoryUsage
object representing the current state of the heap. This incorporates various statistics on both the initial and current memory allocations used by the heap.
- Returns:
- a
MemoryUsage
object for the heap.
public MemoryUsage getNonHeapMemoryUsage()
Returns aMemoryUsage
object representing the current state of non-heap memory. This incorporates various statistics on both the initial and current memory allocations used by non-heap memory..
- Returns:
- a
MemoryUsage
object for non-heap memory.
public int getObjectPendingFinalizationCount()
Returns the number of objects which are waiting to be garbage collected (finalized). An object is finalized when the garbage collector determines that there are no more references to that object are in use.
- Returns:
- the number of objects awaiting finalization.
public boolean isVerbose()
Returns true if the virtual machine will emit additional information when memory is allocated and deallocated. The format of the output is left up to the virtual machine.
- Returns:
- true if verbose memory output is on.
public void setVerbose(boolean verbose)
Turns on or off the emission of additional information when memory is allocated and deallocated. The format of the output is left up to the virtual machine. This method may be called by multiple threads concurrently, but there is only one global setting of verbosity that is affected.
- Parameters:
verbose
- the new setting for verbose memory output.
- Throws:
SecurityException
- if a security manager exists and denies ManagementPermission("control").