db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r467580 - /db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java
Date Wed, 25 Oct 2006 07:52:54 GMT
Author: kahatlen
Date: Wed Oct 25 00:52:53 2006
New Revision: 467580

URL: http://svn.apache.org/viewvc?view=rev&rev=467580
Log:
DERBY-912: OutOfMemory error on continuous execution of SQL statement

Merged from trunk (svn merge -r 467577:467578 ../trunk).

Modified:
    db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java

Modified: db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java?view=diff&rev=467580&r1=467579&r2=467580
==============================================================================
--- db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java
(original)
+++ db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java
Wed Oct 25 00:52:53 2006
@@ -21,12 +21,14 @@
 
 package org.apache.derby.impl.store.access;
 
+import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Properties;
 import java.util.Vector;
 
 import org.apache.derby.iapi.reference.SQLState;
+import org.apache.derby.iapi.util.ReuseFactory;
 
 import org.apache.derby.iapi.services.context.ContextManager;
 
@@ -120,6 +122,11 @@
 	private Vector sorts;
 	private Vector sortControllers;
 
+    /** List of sort identifiers (represented as <code>Integer</code> objects)
+     * which can be reused. Since sort identifiers are used as array indexes,
+     * we need to reuse them to avoid leaking memory (DERBY-912). */
+    private ArrayList freeSortIds;
+
 	/**
 	Where to look for temporary conglomerates.
 	**/
@@ -163,6 +170,7 @@
 		conglomerateControllers = new Vector();
 
 		sorts                   = null; // allocated on demand.
+		freeSortIds             = null; // allocated on demand.
 		sortControllers         = null; // allocated on demand
 
         if (parent_tran != null)
@@ -314,6 +322,7 @@
                         sort.drop(this);
                 }
                 sorts.removeAllElements();
+                freeSortIds.clear();
             }
 		}
 	}
@@ -1717,10 +1726,22 @@
                         estimatedRowSize);
 
 		// Add the sort to the sorts vector
-		if (sorts == null)
+		if (sorts == null) {
 			sorts = new Vector();
-		long sortid = sorts.size();
-		sorts.addElement(sort);
+            freeSortIds = new ArrayList();
+        }
+
+        int sortid;
+        if (freeSortIds.isEmpty()) {
+            // no free identifiers, add sort at the end
+            sortid = sorts.size();
+            sorts.addElement(sort);
+        } else {
+            // reuse a sort identifier
+            sortid = ((Integer) freeSortIds.remove(freeSortIds.size() - 1))
+                .intValue();
+            sorts.setElementAt(sort, sortid);
+        }
 
 		return sortid;
 	}
@@ -1748,6 +1769,7 @@
         {
             sort.drop(this);
             sorts.setElementAt(null, (int) sortid);
+            freeSortIds.add(ReuseFactory.getInteger((int) sortid));
         }
     }
 



Mime
View raw message