cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Kulp <dk...@apache.org>
Subject Re: Use of new String(String value) constructor in CXF codes ?
Date Wed, 26 Sep 2012 14:29:04 GMT

The WSDLManager uses the systemId string that is passed in (and then recorded in the locations
and such) as a key for a WeakHashMap to provide a cache for the WSDL objects and schemas and
such.  However, that does mean we need to be a little careful with those location String objects
to make sure nothing strongly holds onto those objects when they don't need to.   If things
end up being held onto strongly, the caches will never clear and we end up with memory leaks.

In particular, the WSDL holds onto Schemas which are DOM's and would use this method to parse.
 If the DOM comes from the schema in the WSDL, this would result in the system ID recorded
below being the same as the WSDL and thus locking the wsdl in the cache.

In general, creating a copy of the string is relatively cheap.   Not creating a copy and risking
an entire WSDL/DOM being left in memory is not so cheap.

Dan




On Sep 26, 2012, at 5:37 AM, Ivan <xhhsld@gmail.com> wrote:

> While searching the codes, I saw that there are some cxf codes are using
> new String(String value). like in StaxUtils, I am wondering is there any
> special reason for this ?
> 
> public static Document read(XMLStreamReader reader, boolean recordLoc)
> throws XMLStreamException {
>        Document doc = DOMUtils.createDocument();
>        if (reader.getLocation().getSystemId() != null) {
>            try {
>                doc.setDocumentURI(new
> String(reader.getLocation().getSystemId()));
> <-----------------------------------
>            } catch (Exception e) {
>                //ignore - probably not DOM level 3
>            }
>        }
>        readDocElements(doc, doc, reader, true, recordLoc);
>        return doc;
>    }
> 
> Thanks
> 
> -- 
> Ivan

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Mime
View raw message