Author: mrglavas
Date: Wed Sep 13 11:26:56 2006
New Revision: 443059

URL: http://svn.apache.org/viewvc?view=rev&rev=443059
Log:
Once the DOMParser has completed building the DOM drop all internal references
to the completed Document object. If the application is pooling parsers this
will allow the garbage collector to reclaim the Document and all of its nodes
if the application no longer has any references to it.

Modified:
    xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAnnotationImpl.java
    xerces/java/trunk/src/org/apache/xerces/jaxp/DocumentBuilderImpl.java
    xerces/java/trunk/src/org/apache/xerces/parsers/AbstractDOMParser.java
    xerces/java/trunk/src/org/apache/xerces/parsers/DOMParserImpl.java

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAnnotationImpl.java
URL: 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAnnotationImpl.java?view=diff&rev=443059&r1=443058&r2=443059
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAnnotationImpl.java 
(original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAnnotationImpl.java Wed 
Sep 13 11:26:56 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -162,6 +162,7 @@
             // ditto with above
         }
         Document aDocument = parser.getDocument();
+        parser.dropDocumentReferences();
         Element annotation = aDocument.getDocumentElement();
         Node newElem = null;
         if (futureOwner instanceof CoreDocumentImpl) {

Modified: xerces/java/trunk/src/org/apache/xerces/jaxp/DocumentBuilderImpl.java
URL: 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/jaxp/DocumentBuilderImpl.java?view=diff&rev=443059&r1=443058&r2=443059
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/jaxp/DocumentBuilderImpl.java 
(original)
+++ xerces/java/trunk/src/org/apache/xerces/jaxp/DocumentBuilderImpl.java Wed 
Sep 13 11:26:56 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2005 The Apache Software Foundation.
+ * Copyright 2000-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -281,7 +281,9 @@
             resetSchemaValidator();
         }
         domParser.parse(is);
-        return domParser.getDocument();
+        Document doc = domParser.getDocument();
+        domParser.dropDocumentReferences();
+        return doc;
     }
 
     public boolean isNamespaceAware() {

Modified: xerces/java/trunk/src/org/apache/xerces/parsers/AbstractDOMParser.java
URL: 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/parsers/AbstractDOMParser.java?view=diff&rev=443059&r1=443058&r2=443059
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/parsers/AbstractDOMParser.java 
(original)
+++ xerces/java/trunk/src/org/apache/xerces/parsers/AbstractDOMParser.java Wed 
Sep 13 11:26:56 2006
@@ -368,6 +368,19 @@
     public Document getDocument () {
         return fDocument;
     } // getDocument():Document
+    
+    /** 
+     * Drops all references to the last DOM which was built by this parser.
+     */
+    public final void dropDocumentReferences() {
+        fDocument = null;
+        fDocumentImpl = null;
+        fDeferredDocumentImpl = null;
+        fDocumentType = null;
+        fCurrentNode = null;
+        fCurrentCDATASection = null;
+        fCurrentEntityDecl = null;
+    } // dropDocumentReferences()
 
     //
     // XMLDocumentParser methods

Modified: xerces/java/trunk/src/org/apache/xerces/parsers/DOMParserImpl.java
URL: 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/parsers/DOMParserImpl.java?view=diff&rev=443059&r1=443058&r2=443059
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/parsers/DOMParserImpl.java 
(original)
+++ xerces/java/trunk/src/org/apache/xerces/parsers/DOMParserImpl.java Wed Sep 
13 11:26:56 2006
@@ -65,7 +65,6 @@
 import org.w3c.dom.ls.LSResourceResolver;
 import org.xml.sax.SAXException;
 
-
 /**
  * This is Xerces DOM Builder class. It uses the abstract DOM
  * parser with a document scanner, a dtd scanner, and a validator, as
@@ -76,12 +75,8 @@
  * @author Rahul Srivastava, Sun Microsystems Inc.
  * @version $Id$
  */
-
-
 public class DOMParserImpl
-extends AbstractDOMParser implements LSParser, DOMConfiguration {
-
-
+    extends AbstractDOMParser implements LSParser, DOMConfiguration {
 
     // SAX & Xerces feature ids
 
@@ -899,7 +894,9 @@
                 throw (LSException) 
DOMUtil.createLSException(LSException.PARSE_ERR, e).fillInStackTrace();
             }
         }
-        return getDocument ();
+        Document doc = getDocument();
+        dropDocumentReferences();
+        return doc;
     }
 
     /**
@@ -954,7 +951,9 @@
                 throw (LSException) 
DOMUtil.createLSException(LSException.PARSE_ERR, e).fillInStackTrace();
             }
         }
-        return getDocument ();
+        Document doc = getDocument();
+        dropDocumentReferences();
+        return doc;
     }
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to