GF4J 0.9.4 Beta

gameframe.util
Class ObjectPreserver

java.lang.Object
  |
  +--gameframe.util.ObjectPreserver
All Implemented Interfaces:
java.lang.Runnable

public class ObjectPreserver
extends java.lang.Object
implements java.lang.Runnable

This class has methods to ensure that an object is never garbage collected. It is very handy when using singletons (classes that have one static reference to itself) as these might be garbage collected in some Java runtimes.

Since:
GameFrame for Java 0.9.2
Version:
GameFrame for Java 0.9.4

Field Summary
private static java.util.Vector mStatic_protectedSet
          As this class isn't garbage collected, neither is this vector of or the objects the vector references.
private static ObjectPreserver mStatic_singletonInstance
          This keeps this class and everything it references from being garbage collected by having an active thread and containing all the objects being preserved in a member varialbe.
 
Constructor Summary
private ObjectPreserver()
          Constructs the object preserver and starts up the thread that keeps this object alive.
 
Method Summary
static void preserveObject(java.lang.Object object)
          The objects passed to this method will be protected from garbage collection until they are released by the unpreserveObject method.
 void run()
          The threads run method that does nothing else than keeps this object alive.
 void stop()
          Stops the garbage collector preventing thread.
static void unpreserveObject(java.lang.Object object)
          The objects passed to this method will no longer be protected from garbage collection.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

mStatic_singletonInstance

private static ObjectPreserver mStatic_singletonInstance
This keeps this class and everything it references from being garbage collected by having an active thread and containing all the objects being preserved in a member varialbe.
Since:
GameFrame for Java 0.9.2

mStatic_protectedSet

private static java.util.Vector mStatic_protectedSet
As this class isn't garbage collected, neither is this vector of or the objects the vector references.
Since:
GameFrame for Java 0.9.2
Constructor Detail

ObjectPreserver

private ObjectPreserver()
Constructs the object preserver and starts up the thread that keeps this object alive.
Method Detail

run

public void run()
The threads run method that does nothing else than keeps this object alive.
Specified by:
run in interface java.lang.Runnable
Since:
GameFrame for Java 0.9.2

stop

public void stop()
Stops the garbage collector preventing thread.
Since:
GameFrame for Java 0.9.2

preserveObject

public static void preserveObject(java.lang.Object object)
The objects passed to this method will be protected from garbage collection until they are released by the unpreserveObject method.
Parameters:
object - The object to be added to the preserved set of objects.
Since:
GameFrame for Java 0.9.2

unpreserveObject

public static void unpreserveObject(java.lang.Object object)
The objects passed to this method will no longer be protected from garbage collection.
Parameters:
object - The object to be removed from the preserved set of objects.
Since:
GameFrame for Java 0.9.2

GF4J 0.9.4 Beta