Author: jm
Date: 2012-07-05 13:26:54 -0700 (Thu, 05 Jul 2012)
New Revision: 29769
Modified:
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/AbstractTunableHandler.java
Log:
Fixes #1221: Fixed memory leak in AbstractTunableHandler
Modified:
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/AbstractTunableHandler.java
===================================================================
---
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/AbstractTunableHandler.java
2012-07-05 19:57:39 UTC (rev 29768)
+++
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/AbstractTunableHandler.java
2012-07-05 20:26:54 UTC (rev 29769)
@@ -1,6 +1,8 @@
package org.cytoscape.work;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -20,7 +22,7 @@
private final Field field;
private final Method getter;
private final Method setter;
- private final Object instance;
+ private final Reference<?> instance;
private final Tunable tunable;
/**
@@ -37,7 +39,7 @@
this.field = field;
this.getter = null;
this.setter = null;
- this.instance = instance;
+ this.instance = new WeakReference<Object>(instance);
this.tunable = tunable;
}
@@ -56,7 +58,7 @@
this.field = null;
this.getter = getter;
this.setter = setter;
- this.instance = instance;
+ this.instance = new WeakReference<Object>(instance);
this.tunable = tunable;
}
@@ -71,7 +73,7 @@
* {@inheritDoc}
*/
public final Object getValue() throws IllegalAccessException,
InvocationTargetException {
- return field != null ? field.get(instance) :
getter.invoke(instance);
+ return field != null ? field.get(instance.get()) :
getter.invoke(instance.get());
}
/**
@@ -80,9 +82,9 @@
public void setValue(final Object newValue) throws
IllegalAccessException, InvocationTargetException {
if (field != null)
- field.set(instance, newValue);
+ field.set(instance.get(), newValue);
else
- setter.invoke(instance, newValue);
+ setter.invoke(instance.get(), newValue);
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.