[concurrency-interest] Memory Leak in LinkedBlockingQueue

Thierry Hanot thanot@infovista.com
Thu, 27 Jan 2005 09:41:39 +0100


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C5044C.04B036D0
Content-Type: text/plain

Sorry a few typo in my previous mail ... the problem is in the poll method
not offer ... 
 

-----Original Message-----
From: Thierry Hanot [mailto:thanot@infovista.com] 
Sent: Thursday, January 27, 2005 8:36 AM
To: concurrency-interest@altair.cs.oswego.edu
Subject: [concurrency-interest] Memory Leak in LinkedBlockingQueue


Hi 
 
I don't know if there is an open bug in the sun database( i've searched for
it but nothing )  but the simple following test case 
cause an out of memory every times on Windows 2000 with the jdk 1.5.0 :
 
 
 
public class PollMemoryLeak {
    public static void main(String[] args) throws InterruptedException {
        BlockingQueue  bl = new LinkedBlockingQueue(2000);
        while(true){
            bl.poll( 2,TimeUnit.MILLISECONDS);
        }
}
 
The number of AbstractQueuedSynchronizer.Node Object is increasing
constantly.( as the node are really small objects it take a little time to
crash ) 
 
 
After a small investigation in a debugger , it seems that the memory leak is
in the AbstractQueuedSynchronizer.java in ConditionObject( All the
synchronized queue should have 
the same problem ).
 
It seem's that the nextWaiter on the node is never resetted when the end of
poll is reached. That means at every called to  poll a new Node is allocated
but none of them are removed since they all references each other with the
nextWaiter.( Node are double chained list if i'm rigth and only one chain is
broken with the setHead  ) .
 
I'm using concurrency since a while but it's was my first looks inside the
code of the JSR166 , so may be my analysis is not relevant .
 
Thks
 
Thierry 
 
 
 


------_=_NextPart_001_01C5044C.04B036D0
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Message</TITLE>

<META content="MSHTML 6.00.2800.1479" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=192174008-27012005>Sorry 
a few typo in my previous mail ... the problem is in the poll method not offer 
... </SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN 
class=192174008-27012005></SPAN></FONT>&nbsp;</DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <DIV></DIV>
  <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT 
  face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> Thierry Hanot 
  [mailto:thanot@infovista.com] <BR><B>Sent:</B> Thursday, January 27, 2005 8:36 
  AM<BR><B>To:</B> concurrency-interest@altair.cs.oswego.edu<BR><B>Subject:</B> 
  [concurrency-interest] Memory Leak in LinkedBlockingQueue<BR><BR></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN class=739015819-26012005>Hi 
  </SPAN></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2><SPAN class=739015819-26012005>I don't know if 
  there is an open bug in the sun database( i've searched for it but nothing 
  )&nbsp; but the simple following test case </SPAN></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN class=739015819-26012005>cause an out of 
  memory every times on Windows 2000 with the jdk 1.5.0 :</SPAN></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2><SPAN class=739015819-26012005>public class 
  PollMemoryLeak {</SPAN></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN class=739015819-26012005>&nbsp;&nbsp;&nbsp; 
  public static void main(String[] args) throws InterruptedException 
  {</SPAN></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  BlockingQueue&nbsp; bl = new LinkedBlockingQueue(2000);</SPAN></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  while(true){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  bl.poll( 
  2,TimeUnit.MILLISECONDS);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  }</SPAN></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005>}</SPAN></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2><SPAN class=739015819-26012005>The number of 
  AbstractQueuedSynchronizer.Node Object is increasing constantly.( as the node 
  are really small objects it take a little time to crash ) </SPAN></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2><SPAN class=739015819-26012005>After a small 
  investigation in a debugger , it seems that the memory leak is in the 
  AbstractQueuedSynchronizer.java&nbsp;in ConditionObject( All the synchronized 
  queue should have </SPAN></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN class=739015819-26012005>the same problem 
  ).</SPAN></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2><SPAN class=739015819-26012005>It seem's that the 
  nextWaiter on the node is never resetted when the end of&nbsp;<SPAN 
  class=192174008-27012005><FONT 
  color=#0000ff><STRONG>&nbsp;poll</STRONG>&nbsp;</FONT></SPAN>is reached. That 
  means at every called to&nbsp;<SPAN class=192174008-27012005><FONT 
  color=#0000ff>&nbsp;<STRONG>poll</STRONG>&nbsp;</FONT></SPAN>a new Node is 
  allocated but none of them are removed since they all references each other 
  with the nextWaiter.( Node are double chained list if&nbsp;i'm rigth 
  and&nbsp;only one chain is broken with the setHead &nbsp;) 
  .</SPAN></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2><SPAN class=739015819-26012005>I'm using 
  concurrency since a while but it's was my first looks inside the code of the 
  JSR166 , so may be my analysis is not relevant .</SPAN></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005>Thks</SPAN></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2><SPAN class=739015819-26012005>Thierry 
  </SPAN></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=739015819-26012005></SPAN></FONT>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C5044C.04B036D0--