Name: nt126004 Date: 02/01/2002
FULL PRODUCT VERSION :
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
If you extend a Reference class such as WeakReference and
override the clear/enqueue methods, the overridden methods
are never called even if the Garbage Collector actually
enqueues/clears the references. If this is the desired
behaviour, it may be advisable to declare these methods as
final in the Reference classes.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Run the given program.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package com.daffodilwoods.codare.testcases;
import java.lang.ref.*;
public class TCWeakReferenceEnqueue {
public TCWeakReferenceEnqueue() {
}
public static void main(String[] args) {
try{
Integer integer = new Integer(1);
ExtendedWeakReference weakReference = new ExtendedWeakReference
(integer);
integer = null;
System.out.println("Before Garbage Collected : " + weakReference.get
());
System.gc();
System.out.println("After Garbage Collected : " + weakReference.get
());
Thread.sleep(5000);
System.out.println("After Thread Execution : " + weakReference.get
());
}
catch(Exception E){
E.printStackTrace();
}
}
}
class ExtendedWeakReference extends WeakReference {
public ExtendedWeakReference(Object k) {
super(k);
}
public ExtendedWeakReference(Object k, ReferenceQueue q) {
super(k, q);
}
public void clear(){
System.out.println("Clear called");
super.clear();
}
public boolean enqueue(){
System.out.println("Enqueue called");
return super.enqueue();
}
}
}
---------- END SOURCE ----------
(Review ID: 138225)
======================================================================
FULL PRODUCT VERSION :
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
If you extend a Reference class such as WeakReference and
override the clear/enqueue methods, the overridden methods
are never called even if the Garbage Collector actually
enqueues/clears the references. If this is the desired
behaviour, it may be advisable to declare these methods as
final in the Reference classes.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Run the given program.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package com.daffodilwoods.codare.testcases;
import java.lang.ref.*;
public class TCWeakReferenceEnqueue {
public TCWeakReferenceEnqueue() {
}
public static void main(String[] args) {
try{
Integer integer = new Integer(1);
ExtendedWeakReference weakReference = new ExtendedWeakReference
(integer);
integer = null;
System.out.println("Before Garbage Collected : " + weakReference.get
());
System.gc();
System.out.println("After Garbage Collected : " + weakReference.get
());
Thread.sleep(5000);
System.out.println("After Thread Execution : " + weakReference.get
());
}
catch(Exception E){
E.printStackTrace();
}
}
}
class ExtendedWeakReference extends WeakReference {
public ExtendedWeakReference(Object k) {
super(k);
}
public ExtendedWeakReference(Object k, ReferenceQueue q) {
super(k, q);
}
public void clear(){
System.out.println("Clear called");
super.clear();
}
public boolean enqueue(){
System.out.println("Enqueue called");
return super.enqueue();
}
}
}
---------- END SOURCE ----------
(Review ID: 138225)
======================================================================
- duplicates
-
JDK-4386925 (ref spec) Clarify specification to note that enqueue() and clear() are not invoked by the GC
-
- Resolved
-