title: Memory leak in a Java web application
body: <p>I have a Java web application running on Tomcat 7 that appears to have a memory leak. The average memory usage of the application increases linearly over time when under load (determined using JConsole). After the memory usage reaches the plateau, performance degrades significantly. Response times go from ~100ms to [300ms, 2500ms], so this is actually causing real problems.</p>
  
  <p><strong>JConsole memory profile of my application:</strong>
  <img src="https://i.stack.imgur.com/vROVt.png" alt="application memory profile"></p>
  
  <p>Using VisualVM, I see that at least half the memory is being used by character arrays (i.e. char[]) and that most (roughly the same number of each, 300,000 instances) of the strings are one of the following: "Allocation Failure", "Copy", "end of minor GC", all of which seem to be related to garbage collection notification. As far as I know, the application doesn't monitor the garbage collector at all. VisualVM can't find a GC root for any of these strings, so I'm having a hard time tracking this down.</p>
  
  <p><strong>Memory Analyzer heap dump:</strong>
  <img src="https://i.stack.imgur.com/AFKCj.png" alt="heap dump, unreachable memory"></p>
  
  <p>I can't explain why the memory usage plateaus like that, but I have a theory as to why performance degrades once it does. If memory is fragmented, the application could take a long time to allocate a contiguous block of memory to handle new requests.</p>
  
  <p>Comparing this to the built-in Tomcat server status application, the memory increases and levels off at, but doesn't hit a high "floor" like my application. It also doesn't have the high number of unreachable char[].</p>
  
  <p><strong>JConsole memory profile of Tomcat server status application:</strong>
  <img src="https://i.stack.imgur.com/cHfAy.png" alt="enter image description here"></p>
  
  <p><strong>Memory Analyzer heap dump of Tomcat server status applicationp:</strong>
  <img src="https://i.stack.imgur.com/9NaDu.png" alt="enter image description here"></p>
  
  <p>Where could these strings be allocated and why are they not being garbage collected? Are there Tomcat or Java settings that could affect this? Are there specific packages that could be affect this?</p>