You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by st...@apache.org on 2006/10/05 17:48:32 UTC
svn commit: r453274 - in /ant/core/trunk/src/main/org/apache/tools/ant/util:
WeakishReference.java optional/WeakishReference12.java
Author: stevel
Date: Thu Oct 5 08:48:31 2006
New Revision: 453274
URL: http://svn.apache.org/viewvc?view=rev&rev=453274
Log:
refactoring of WeakishReference, as discussed.
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/util/WeakishReference.java
ant/core/trunk/src/main/org/apache/tools/ant/util/optional/WeakishReference12.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/WeakishReference.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/WeakishReference.java?view=diff&rev=453274&r1=453273&r2=453274
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/WeakishReference.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/WeakishReference.java Thu Oct 5 08:48:31 2006
@@ -18,24 +18,34 @@
package org.apache.tools.ant.util;
-import org.apache.tools.ant.util.optional.WeakishReference12;
+
+import java.lang.ref.WeakReference;
/**
- * This is a weak reference on java1.2 and up, that is all
- * platforms Ant1.6 supports.
+ * These classes are part of some code to reduce memory leaks by only retaining weak references to things
+ * on Java1.2+, and yet still work (with leaky hard references) on Java1.1. Now that Ant is 1.2+ only,
+ * life is simpler and none of the classes are needed any more.
+ *
+ * They are only retained in case a third-party task uses them
* @since ant1.6
- * @deprecated since 1.7.
+ * @see org.apache.tools.ant.util.optional.WeakishReference12
+ * @deprecated deprecated 1.7; will be removed in Ant1.8
* Just use {@link java.lang.ref.WeakReference} directly.
*/
-public abstract class WeakishReference {
+public class WeakishReference {
+
+
+ private WeakReference weakref;
/**
- * create the appropriate type of reference for the java version
- * @param object the object that the reference will refer to.
- * @return reference to the Object.
+ * create a new soft reference, which is bound to a
+ * Weak reference inside
+ *
+ * @param reference
+ * @see java.lang.ref.WeakReference
*/
- public static WeakishReference createReference(Object object) {
- return new WeakishReference12(object);
+ WeakishReference(Object reference) {
+ this.weakref = new WeakReference(reference);
}
/**
@@ -45,31 +55,35 @@
* @return The object to which this reference refers, or
* <code>null</code> if this reference object has been cleared.
*/
- public abstract Object get();
+ public Object get() {
+ return weakref.get();
+ }
/**
- * A hard reference for Java 1.1.
+ * create the appropriate type of reference for the java version
+ * @param object the object that the reference will refer to.
+ * @return reference to the Object.
+ */
+ public static WeakishReference createReference(Object object) {
+ return new WeakishReference(object);
+ }
+
+
+ /**
+ * This was a hard reference for Java 1.1. Since Ant1.7,
* @deprecated since 1.7.
* Hopefully nobody is using this.
*/
public static class HardReference extends WeakishReference {
- private Object object;
/**
* constructor.
* @param object the object that the reference will refer to.
*/
public HardReference(Object object) {
- this.object = object;
+ super(object);
}
- /**
- * Returns this reference object's referent.
- * @return the object to which this reference refers.
- */
- public Object get() {
- return object;
- }
}
}
Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/optional/WeakishReference12.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/optional/WeakishReference12.java?view=diff&rev=453274&r1=453273&r2=453274
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/optional/WeakishReference12.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/optional/WeakishReference12.java Thu Oct 5 08:48:31 2006
@@ -27,10 +27,13 @@
* appropriate java.lang.ref class.
* @deprecated since 1.7.
* Just use {@link WeakReference} directly.
+ * Note that in ant1.7 is parent was changed to extend HardReference.
+ * This is because the latter has access to the (package scoped)
+ * WeakishReference(Object) constructor, and both that and this are thin
+ * facades on the underlying no-longer-abstract base class.
*/
-public class WeakishReference12 extends WeakishReference {
+public class WeakishReference12 extends WeakishReference.HardReference {
- private WeakReference weakref;
/**
* create a new soft reference, which is bound to a
@@ -39,16 +42,6 @@
* @see java.lang.ref.WeakReference
*/
public WeakishReference12(Object reference) {
- this.weakref = new WeakReference(reference);
+ super(reference);
}
-
- /**
- * Returns this reference object's referent.
- *
- * @return referent.
- */
- public Object get() {
- return weakref.get();
- }
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org