JDK-6539568 : Memory leak in AbstractQueuedSynchronizer.cancelAcquire(Node)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-03-28
  • Updated: 2010-04-04
  • Resolved: 2007-03-28
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
When java.util.concurrent.locks.ReentrantLock.lockInterruptibly() is locked, memory is leaked.

The leak appears to originate in:
java.util.concurrent.locks.AbstractQueuedSynchronizer.cancelAcquire(Node), which removes a node from the queue without zeroing out its prev and next fields.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached test program.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
  Program runs for an indefinite period with a constant memory footprint.
ACTUAL -
Process memory increased monotonically.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.concurrent.locks.ReentrantLock;

public class LockInterruptMemoryLeakBug
{
   public static void main(String[] args){
      final ReentrantLock lock = new ReentrantLock();
      
      Thread testThread = new Thread(){
         public void run(){
            while(true){
               try{
                  lock.lockInterruptibly();
                  lock.unlock();
               }catch(InterruptedException e){}
            }
         }
      };
      lock.lock();
      testThread.start();
      while(true){
         testThread.interrupt();
      }
   }
}
---------- END SOURCE ----------

Comments
EVALUATION This is a duplicate of 6460501: Synchronizer timed acquire still leaks memory which is (or soon will be) fixed in jdk7 b06, 6u2, 5.0u12. I've verified those fixes with the submitter's test case.
28-03-2007