(reflect spec) Clarify that GC does not itself invoke the clear method

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P4
    • None
    • Affects Version/s: 1.3.0
    • Component/s: core-libs
    • Fix Understood
    • generic
    • generic



      Name: krC82822 Date: 11/02/2000


      2 Nov 2000, eval1127@eng -- reproduced with 1.3.0 (Solaris).
      See also # 4239645, 4278871.
      -----------
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)


      When a SoftReference is cleared, the clear method on the subclass is not called.

      The JDK documentation explicitly states that we can derive a Reference. So I
      don't see what I'm doing wrong. It should be a bug.

        To reproduce the problem, launch the following example with the command:

      java -mx1m RefBug you will see:

      D:\Users\Jolif\Essais>java -mx1m RefBug
      Soft reference created
      in soft [Ljava.lang.String;@3fbdb0
      in soft [Ljava.lang.String;@3fbdb0
      in soft null << the clear method has not been called !


      import java.lang.ref.*;

      public class RefBug
      {
        private static class MySoftReference extends SoftReference
        {
          public MySoftReference(Object referent)
          {
            super(referent);
            System.out.println("Soft reference created");
          }

          public void clear()
          {
            super.clear();
            System.out.println("I just clear()'d my ref");
          }
        }
        
        // CJO 10/00
        public static void main(String arg[])
        {
          SoftReference ref = new MySoftReference(new String[10000]);
          
          System.out.println("in soft "+ref.get());
          
          String[] array = new String[10000];
          
          System.out.println("in soft "+ref.get());

          System.gc();
          try {
            Thread.sleep(10000);
          } catch (Exception e) {}
          System.gc();

          System.out.println("in soft "+ref.get());
        }
      }
      (Review ID: 111128)
      ======================================================================

            Assignee:
            Mark Reinhold
            Reporter:
            Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: