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

Memory Leak in PriorityBlockingQueue

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 7u9
    • core-libs
    • None

      FULL PRODUCT VERSION :
      java version " 1.7.0_09 "
      Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
      Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux xxxxx 3.2.0-3-amd64 #1 SMP Mon Jul 23 02:45:17 UTC 2012 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
        PriorityBlockingQueue does not " null " out the last removed element in PriorityBlockingQueue even though the size is zero.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute supplied source code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Size: 0
      Internal data[0]: null
      ACTUAL -
      Size: 0
      Internal data[0]: Remains in internal array

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
          public static void main(String... args) {
              PriorityBlockingQueue<String> pbq = new PriorityBlockingQueue<String>();

              pbq.add( " Remains in internal array " );
              pbq.poll();
              System.out.println( " Size: " +pbq.size());

              try {
                  Field queueFld = PriorityBlockingQueue.class.getDeclaredField( " queue " );
                  queueFld.setAccessible(true);
                  System.out.println( " Internal data[0]: " +((Object[])queueFld.get(pbq))[0]);
              }
              catch( Exception ex) {
                  ex.printStackTrace();
              }
          }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None.
      1.) The internal " queue " field and all managing methods are private, so that creating a custom derived version doesn't work.
      2.) Since such queues are typically used in concurrent environment, adding and removing a dummy entry (once the queue size is zero) is also no solution

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: