| Method from sun.java2d.Disposer Detail: |
synchronized void add(Object target,
DisposerRecord rec) {
if (target instanceof DisposerTarget) {
target = ((DisposerTarget)target).getDisposerReferent();
}
java.lang.ref.Reference ref;
if (refType == PHANTOM) {
ref = new PhantomReference(target, queue);
} else {
ref = new WeakReference(target, queue);
}
records.put(ref, rec);
}
Performs the actual registration of the target object to be disposed. |
public static void addObjectRecord(Object obj,
DisposerRecord rec) {
records.put(new WeakReference(obj, queue) , rec);
}
|
public static void addRecord(Object target,
DisposerRecord rec) {
disposerInstance.add(target, rec);
}
Registers the object and the native data for later disposal. |
public static void addRecord(Object target,
long disposeMethod,
long pData) {
java.security.AccessController.doPrivileged(
new sun.security.action.LoadLibraryAction("awt"));
initIDs();
String type = (String) java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("sun.java2d.reftype"));
if (type != null) {
if (type.equals("weak")) {
refType = WEAK;
System.err.println("Using WEAK refs");
} else {
refType = PHANTOM;
System.err.println("Using PHANTOM refs");
}
}
disposerInstance = new Disposer();
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
/* The thread must be a member of a thread group
* which will not get GCed before VM exit.
* Make its parent the top-level thread group.
*/
ThreadGroup tg = Thread.currentThread().getThreadGroup();
for (ThreadGroup tgn = tg;
tgn != null;
tg = tgn, tgn = tg.getParent());
Thread t =
new Thread(tg, disposerInstance, "Java2D Disposer");
t.setDaemon(true);
t.setPriority(Thread.MAX_PRIORITY);
t.start();
return null;
}
}
);
disposerInstance.add(target,
new DefaultDisposerRecord(disposeMethod, pData));
}
Registers the object and the native data for later disposal. |
public static void addReference(Reference ref,
DisposerRecord rec) {
records.put(ref, rec);
}
|
public static ReferenceQueue getQueue() {
return queue;
}
|
public void run() {
while (true) {
try {
Object obj = queue.remove();
((Reference)obj).clear();
DisposerRecord rec = (DisposerRecord)records.remove(obj);
rec.dispose();
obj = null;
rec = null;
} catch (Exception e) {
System.out.println("Exception while removing reference: " + e);
e.printStackTrace();
}
}
}
|