JDK-8011941 : Memory Leak in PriorityBlockingQueue
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 7u9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2013-03-20
  • Updated: 2013-04-11
  • Resolved: 2013-04-11
Related Reports
Duplicate :  
Description
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
Comments
Fixed in 7u12
11-04-2013