public class Immortals extends Object
An immortal object has two major properties:
|Constructor and Description|
|Modifier and Type||Method and Description|
Turns the given object and all objects referred from it into immortal objects.
Returns the amount of free immortal memory still available.
Gets whether an object is immortal or not.
Calls the method
Turns the given object into an immortal object.
Returns the total amount of immortal memory.
public static <T> T deepImmortal(T root)
Weakly reachable objects are not turned into immortal objects.
T- the root object type
root- the root of the objects graph to turn into immortal
public static long freeMemory()
public static boolean isImmortal(Object o)
An object is immortal:
o- the object to check
trueif the queried object is immortal or immutable,
NullPointerException- if given object is null
public static void run(Runnable runnable)
Runnable.run()of the given runnable.
All the objects allocated in the context of this method are directly
allocated as immortals. While the
Runnable.run() method of the
runnable executes all created objects are allocated as immortal objects.
runnable- the runnable to execute
NullPointerException- if the given runnable is
public static <T> T setImmortal(T o)
If the received object was immutable, it remains immutable.
If the object was already immortal, it remains immortal.
If the object was a reclaimable object it turns into an immortal object. Upon
success, the returned object is immortal, otherwise an
OutOfMemoryError is thrown.
T- the object type
o- the object to turn into an immortal
OutOfMemoryError- if the immortal memory is full
public static long totalMemory()
Note that the amount of memory required to hold an object of any given type may be implementation-dependent.