title: OutOfMemoryError: PermGen Space -- Jasper Report with Spring running on Tomcat
body: <p>Our web application encounter a complicated situation</p>
  
  <p>It is a Spring application developed by STS/<code>Tomcat 7</code>. After the application been integrated with <code>Jasper report 4.6.0</code>, it always throw `OutOfMemoryError:  PermGen Space. Then the only way to get it work is to restart the application. But after a while it happen again.
  Here is log before the exception:</p>
  
  <pre><code>Oct 17, 2012 3:42:27 PM org.apache.jasper.compiler.TldLocationsCache tldScanJar
  INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
  Oct 17, 2012 3:42:30 PM org.apache.catalina.core.ApplicationDispatcher invoke
  SEVERE: Servlet.service() for servlet jsp threw exception
  </code></pre>
  
  <p>Here is a section within the exception where I found something about <code>Jasper</code>:</p>
  
  <pre><code>at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:442)
  at org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
  at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
  at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
  at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
  at org.apache.jasper.servlet.JspServletWrapper.loadTagFile(JspServletWrapper.java:240)
  at org.apache.jasper.compiler.TagFileProcessor.loadTagFile(TagFileProcessor.java:578)
  at org.apache.jasper.compiler.TagFileProcessor.access$000(TagFileProcessor.java:49)
  at org.apache.jasper.compiler.TagFileProcessor$TagFileLoaderVisitor.visit(TagFileProcessor.java:655)
  </code></pre>
  
  <p>Here are a few findings when the situation occurs:</p>
  
  <ol>
  <li><p>The issue can happen on page without any Jasper Report components. It seems the Jasper Report bean is trying to find a tag lib all the time when <code>a request is processed by the back end and responded to the front end</code>. Normally from log file I can see above exception will not throw until all back end operations(JPA management) are complete</p></li>
  <li><p>When run log4J on debug mode, I see tons of information showing something like parsing/rendering the all components from Jasper template(textfields, pen, box...), there is a small cut from the huge log:</p>
  
  <pre><code>2012-10-17 15:29:12,025 -- DEBUG -- org.apache.commons.digester.Digester.sax -- startElement(http://jasperreports.sourceforge.net/jasperreports,textElement,textElement)
  2012-10-17 15:29:12,025 -- DEBUG -- org.apache.commons.digester.Digester --   Pushing body text ''
  2012-10-17 15:29:12,025 -- DEBUG -- org.apache.commons.digester.Digester --   New match='jasperReport/summary/band/textField/textElement'
  2012-10-17 15:29:12,025 -- DEBUG -- org.apache.commons.digester.Digester --   Fire begin() for FactoryCreateRule[className=net.sf.jasperreports.engine.xml.JRTextElementFactory, attributeName=null, creationFactory=net.sf.jasperreports.engine.xml.JRTextElementFactory@12dc6007]
  2012-10-17 15:29:12,025 -- DEBUG -- org.apache.commons.digester.Digester -- [FactoryCreateRule]{jasperReport/summary/band/textField/textElement} New net.sf.jasperreports.engine.design.JRDesignTextField
  2012-10-17 15:29:12,025 -- DEBUG -- org.apache.commons.digester.Digester.sax -- ignorableWhitespace()
  </code></pre>
  
  <p>Still, this log is generated when a request to the page which does not contains any Jasper component.</p></li>
  </ol>
  
  <p>I did some research but still cannot find the solution to this issue. </p>
  
  <ol>
  <li><p>The first question is even there is a <code>jasperreport bean</code> in the application why it is always running when it is not even autowired with current service(meaning current page doesn't have any jasper component). Is there a solution/answer to this situation?</p></li>
  <li><p>Also from the exception message
       At least one JAR was scanned for TLDs yet contained no TLDs.
       at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:442)</p>
  
  <p>should comes from Tomcat, and <code>Tomcat never contains any JSTL jar</code>, then I assume it cannot find a match TLD to parse jasper report hence do a full scan of all jars. If so, then how come there is huge amount of debug logs from <code>org.apache.commons.digester.Digester</code> actually seems busy on parsing the jasper template?</p></li>
  </ol>
  
  <p>In general, make this thread is just try to figure out a solution to the probelm, and also find an answer to why Jasper is so active on a place doesn't require it, and how we can let tomcat properly parsed the templates?</p>
  
  <p>Apologize if too verbose, and thanks for any hints.</p>