Bug 25623 - The forEach JSTL tag doesn't release items
Summary: The forEach JSTL tag doesn't release items
Status: RESOLVED WONTFIX
Alias: None
Product: Taglibs
Classification: Unclassified
Component: Standard Taglib (show other bugs)
Version: unspecified
Hardware: All other
: P3 normal with 4 votes (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
: 50661 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-12-18 11:59 UTC by Alex
Modified: 2011-01-27 02:57 UTC (History)
2 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex 2003-12-18 11:59:37 UTC
The forEach tag after pooling doesn't allow items to be garbage collected.
JVM profiler indicates, that org\apache\taglibs\standard\tag\el\core\ForEachTag 
class 'items' member still have references to objects, even after all sessions 
timeout and garbage collector run. The same thing happens with 'c:set' tags - 
they holds references to objects in 'target' member. May be it is a bug in 
Tomcat with invoke 'release()' method? I try to use all Tomcat 4.1.x versions. 
They all acts the same. After this I try to use Struts 'logic:iterate' tag, and 
all objects will be garbage collected successfully.
Comment 1 Felipe Leme 2004-03-25 03:04:53 UTC
There's been a thread about this issue in the mailing list:

http://nagoya.apache.org/eyebrowse/BrowseList?listId=43&by=thread&from=682274
Comment 2 Felipe Leme 2004-05-12 00:27:02 UTC
CC'ing the taglibs-dev address to all Standard bugs. 
Comment 3 Justyna Horwat 2004-06-15 21:24:28 UTC
From the tag author's point of view I believe that the JSTL tag handler's are doing the right thing. In the 
forEach tag, the release method sets the items to null. The tag handler instance can be reused if tag 
pooling is enabled and if another custom action uses the same set of attributes. 

The strut's tags explicitly set items to null in the doEndTag() method. The struts implementation 
violates the tag pooling contract and can end up needlessly destroying and creating items between 
invocations of doStartTag and doEndTag.

Now, on to how the container manages the jsp lifecycle and when release is actually called. If you look 
at the Tomcat 5 jasper (jsp) implemenation you will see a Generator that generates the java servlet 
source code given a jsp. This Generator creates a _jspDestroy() method. Here is the method from one of 
my generated servlet files:

----
  public void _jspDestroy() {
    _jspx_tagPool_c_out_value_nobody.release();
    _jspx_tagPool_c_out_value_escapeXml_nobody.release();
  } 
----

When _jspDestroy() is invoked it calls all the tag handlers in the pool and tells them to invoke their 
release methods.

Now on to when the _jspDestroy() method is invoked. Every servlet that was generated from a jsp page 
extends org.apache.jasper.runtime.HttpJspBase. The HttpJspBase has a destroy() method that invokes 
_jspDestroy(). HttpJspBase.destroy() is invoked whenever Servlet.destroy() is and follows the servlet 
lifecycle.

Now on to the tricky part, the container itself determines when the servlet will be taken out of service 
and can do so for various reasons. It would be difficult to determine when it has done so and when the 
object references are actually freed. It would be interesting to see your profiler results when using a 
different container.

There is a good discussion on container behavior, lifecycle, and tag pooling available in this bug report:

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16001

If you find that you are having issues as a result of the container tag pooling, uou can turn it off in 
Tomcat by setting the init parameter "enablePooling" to "false" in your global $CATALINA_BASE/conf/
web.xml.

This issue seems more in the realm of the container and how it manages objects and tag pools.
Comment 4 Thiago Faria de Andrade 2005-02-23 15:27:59 UTC
It must be a bug. I have developed a big system that uses many JSTL Tags, and 
after some hours I have OutOfMemory error.
I used a profiler and discovered that the SetTag and others tags (some that I 
developed) was not releasing objects in release() method.
Now I'm implementing TryCatchFinally interface in all tags I developed and for 
SetTag I extended it and implemented TryCatchFinally too.

(In reply to comment #0)
> The forEach tag after pooling doesn't allow items to be garbage collected.
> JVM profiler indicates, that 
org\apache\taglibs\standard\tag\el\core\ForEachTag 
> class 'items' member still have references to objects, even after all 
sessions 
> timeout and garbage collector run. The same thing happens with 'c:set' tags - 
> they holds references to objects in 'target' member. May be it is a bug in 
> Tomcat with invoke 'release()' method? I try to use all Tomcat 4.1.x 
versions. 
> They all acts the same. After this I try to use Struts 'logic:iterate' tag, 
and 
> all objects will be garbage collected successfully.

Comment 5 Henri Yandell 2007-08-06 22:04:22 UTC
Based on Justyna's reply, marking this as WONTFIX.
Comment 6 Michael Burton 2008-01-23 13:36:38 UTC
The new location for the nagoya link referenced here seems to be http://issues.apache.org/bugzilla/show_bug.cgi?id=16001
Comment 7 Jeremy Boynes 2011-01-27 02:57:58 UTC
*** Bug 50661 has been marked as a duplicate of this bug. ***