title: Apache HttpComponents EntityUtils memory leak?
body: <p>I executed a 12-hour load test on my Java servlet-based server (Java 1.7 running under WebLogic 12 and Oracle Enterprise Linux). After test has finished, I observed that the memory consumption gradually went up from 500Mb in the beginning of the test to around 3.5Gb (and fluctuated there +/- 500Mb for several hours). 3 days later (server was doing nothing during these 3 days) - I examined memory again, and noticed that nothing out of these 3.5Gb was freed.</p>
  
  <p>To make sure GC is executing, I mad explicit GC using jcmd:</p>
  
  <ul>
  <li>GC.run</li>
  <li>GC.run_finalization</li>
  <li>GC.run</li>
  </ul>
  
  <p>Then, I made a heap snapshot and analyzed with YourKit analyzer (same results with jvisualvm as well).</p>
  
  <p>I noticed that I have 2.5Gb of "Unreachable" objects still being there after 3 days of inactivity. A typical object's incoming references look like this (I'm having ~700K of such objects):</p>
  
  <p><a href="https://i.stack.imgur.com/bQVOI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bQVOI.jpg" alt="enter image description here"></a></p>
  
  <p>I examined Apache HttpComponents code (HttpCore version 4.3.2), and I noticed the following strange code in EntityUtils.toString (which I'm using in my server):</p>
  
  <p><a href="https://i.stack.imgur.com/KclMT.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KclMT.jpg" alt="enter image description here"></a></p>
  
  <p>It looks to me that since <strong>reader</strong> object is not closed - it can create references, eventually causing the leaks I'm observing.</p>
  
  <ul>
  <li>Is this a leaky code of Apache HttpCore EntityUtils?</li>
  <li>Any other reason to have so many unreachable objects after 3 days and after GC.run?</li>
  </ul>
  
  <p>Thank you.</p>