You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2009/12/14 05:31:43 UTC

svn commit: r890173 - /xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/CoreDocumentImpl.java

Author: mrglavas
Date: Mon Dec 14 04:31:42 2009
New Revision: 890173

URL: http://svn.apache.org/viewvc?rev=890173&view=rev
Log:
Fixing JIRA Issue #1356: http://issues.apache.org/jira/browse/XERCESJ-1356. Nodes may be pinned down the map used by compareDocumentPosition() which should be otherwise garbage collectible. Now storing the nodes in a WeakHashMap to eliminate this memory leak. Patch thanks to Ludger Bünger.

Modified:
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/CoreDocumentImpl.java

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/CoreDocumentImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/CoreDocumentImpl.java?rev=890173&r1=890172&r2=890173&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/CoreDocumentImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/CoreDocumentImpl.java Mon Dec 14 04:31:42 2009
@@ -132,7 +132,7 @@
     protected String fDocumentURI;
 
     /** Table for user data attached to this document nodes. */
-    protected Map userData;
+    protected Map userData;  // serialized as Hashtable
 
     /** Identifiers. */
     protected Hashtable identifiers;
@@ -204,7 +204,7 @@
     // document.  Node number values are negative integers.  Nodes are
     // assigned numbers on demand.
     private int nodeCounter = 0;
-    private Hashtable nodeTable;
+    private Map nodeTable;  // serialized as Hashtable
     private boolean xml11Version = false; //by default 1.0
     //
     // Static initialization
@@ -1468,7 +1468,7 @@
         // Node numbers are negative, from -1 to -n
         int num;
         if (nodeTable == null) {
-            nodeTable = new Hashtable();
+            nodeTable = new WeakHashMap();
             num = --nodeCounter;
             nodeTable.put(node, new Integer(num));
         }
@@ -2765,8 +2765,9 @@
     }
     
     /**
-     * Serialized form of user data is a Hashtable. 
-     * Convert it into a WeakHashMap on load.
+     * The serialized forms of the user data and node table
+     * maps are Hashtables. Convert them into WeakHashMaps 
+     * on load.
      */
     private void readObject(ObjectInputStream in)
         throws IOException, ClassNotFoundException {
@@ -2774,25 +2775,34 @@
         if (userData != null) {
             userData = new WeakHashMap(userData);
         }
+        if (nodeTable != null) {
+            nodeTable = new WeakHashMap(nodeTable);
+        }
     }
     
     /**
      * To allow DOM trees serialized by newer versions of Xerces
      * to be read by older versions briefly move the user data
-     * into a Hashtable.
+     * and node table into Hashtables.
      */
     private void writeObject(ObjectOutputStream out) throws IOException {
+        // Keep references to the original objects for restoration after serialization
         final Map oldUserData = this.userData;
+        final Map oldNodeTable = this.nodeTable;
         try {
             if (oldUserData != null) {
                 this.userData = new Hashtable(oldUserData);
-            } 
+            }
+            if (oldNodeTable != null) {
+                nodeTable = new Hashtable(oldNodeTable);
+            }
             out.defaultWriteObject();
         }
         // If the write fails for some reason ensure 
-        // that we restore the original object.
+        // that we restore the original objects.
         finally {
             this.userData = oldUserData;
+            this.nodeTable = oldNodeTable;
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org