You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Eric Burke (JIRA)" <xa...@xml.apache.org> on 2006/06/27 14:18:30 UTC

[jira] Commented: (XALANJ-2195) Memory leak in XMLReaderManager

    [ http://issues.apache.org/jira/browse/XALANJ-2195?page=comments#action_12418018 ] 

Eric Burke commented on XALANJ-2195:
------------------------------------

We see this issue whenever we try to use Java 5. Our app runs fine under 1.4, but when we try to run under Java 5, it runs out of memory after about 4 hours. This is a server-side app running on Linux, JDK 1.5.0_06, and JBoss 4.0.3sp1. I profiled using YourKit Profiler and attached two screen shots showing the leak in action. I edited my own copy of XMLReaderManager like this:

    public synchronized void releaseXMLReader(XMLReader reader) {
        // If the reader that's being released is the cached reader
        // for this thread, mark it as no longer being in use.
        if (m_readers.get() == reader) {
            m_readers.set(null); // ERIC
            m_inUse.put(reader, Boolean.FALSE);
        }
        m_inUse.remove(reader); // ERIC
    }

After that change, the leak is gone.

> Memory leak in XMLReaderManager
> -------------------------------
>
>          Key: XALANJ-2195
>          URL: http://issues.apache.org/jira/browse/XALANJ-2195
>      Project: XalanJ2
>         Type: Bug

>   Components: Xalan
>     Versions: 2.7
>     Reporter: Marko Strukelj
>  Attachments: gc-roots.jpg, retained-object-sizes.jpg
>
> In class org.apache.xml.utils.XMLReaderManager 
> getXMLReader() method creates a new XMLReader (i.e. SAXParser) and stores it into ThreadLocal.
> releaseXMLReader() does not remove (set to null) ThreadLocal thus creating a permanent leak.
> Unfortunately the size of the cached Reader is typically dependent upon the size of the XML document you process (depends on implementation but this is the case with xerces SAXParser). In heavy load server environments with thread pools of tens and hundreds of threads the server sustains a significant memory leak (hundreds of megabytes - depending on the XML document sizes and number of threads in a thread pools).
> A fix is trivial:
> Put the following line at the end of releaseXMLReader method:
> m_readers.set(null);
> I wonder, why is reader stored in ThreadLocal in the first place?

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org