Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4331505

jdb: enablegc does not work for reference, gcollection of which was disabled

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 1.3.0
    • core-svc
    • generic
    • generic

      jdb does not enable garbage collection for objects for which garbage collection was disable earlier by jdb 'disablegc' command.

      To reproduce the problem next class was used.
      Steps:
      * disablegc for created WeakReference wr.
      * enablegc for same object

      import java.lang.ref.*;

      class node {
          byte [] arr;
          node(int size){ arr = new byte[size]; }
      }


      class GC {
           
          public static void GenGarb() {
              int num = 50;
              SoftReference[] srArr = new SoftReference[num];
              WeakReference[] wrArr = new WeakReference[num];

              for (int j = 0;j < num;j++) {
                  for (int i = 0;i < num;i++) {
                      srArr[i] = new SoftReference(new node(90000));
                      wrArr[i] = new WeakReference(new node(90000));
                  }
                  System.gc();
              }
          }
          

          public static void main(String args[]) {
              Runtime rt = Runtime.getRuntime();
              Reference rc;
              ReferenceQueue rq = new ReferenceQueue();
              WeakReference wr = new WeakReference(new node(20000), rq);
              node t;
              int count = 0;
              
              try {
                  while (count++ < 10) {
                      GenGarb();
                      t = (node) wr.get();
                      if (t == null) {
                          rc = rq.poll();
                          System.out.println("Object has been cleared.");
                          wr = new WeakReference(new node(200000), rq);
                      } else {
                          rc = rq.poll();
                           System.out.println("Object is still in memory.");
                      }
                  }
              }catch (OutOfMemoryError e) {
                  System.gc();
                  System.out.println("Failed at the " + count +"th iteration.");
              }
          }
      }

            tbell Tim Bell
            avolkovorcl Alexei Volkov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: