Index: java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
===================================================================
--- java/engine/org/apache/derby/impl/jdbc/EmbedClob.java	(revision 643762)
+++ java/engine/org/apache/derby/impl/jdbc/EmbedClob.java	(working copy)
@@ -79,7 +79,7 @@
     /** Tells whether the Clob has been freed or not. */
     private boolean isValid = true;
 
-    private final int locator;
+    private int locator;
     
     /**
      * Creates an empty Clob object.
@@ -91,7 +91,7 @@
     EmbedClob(EmbedConnection con) throws SQLException {
         super(con);
         this.clob = new TemporaryClob (con.getDBName(), this);
-        this.locator = con.addLOBMapping (this);
+        con.addLOBRefrence (this);
     }
 
     /**
@@ -156,7 +156,7 @@
                 throw se;
             }
         }
-        this.locator = con.addLOBMapping (this);
+        con.addLOBRefrence (this);
     }
 
     /**
@@ -663,6 +663,7 @@
             } catch (IOException e) {
                 throw Util.setStreamFailure(e);
             } finally {
+                localConn.removeLOBMapping(locator);
                 this.clob = null;
             }
         }
@@ -791,6 +792,7 @@
      * @return locator value for this Clob.
      */
     public int getLocator() {
+        locator = localConn.addLOBMapping(this);
         return locator;
     }
 }
Index: java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
===================================================================
--- java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java	(revision 643762)
+++ java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java	(working copy)
@@ -21,6 +21,8 @@
 
 package org.apache.derby.impl.jdbc;
 
+import java.util.Map;
+import java.util.WeakHashMap;
 import org.apache.derby.iapi.error.ExceptionSeverity;
 import org.apache.derby.jdbc.InternalDriver;
 
@@ -130,6 +132,7 @@
 
 	private HashMap lobHashMap = null;
 	private int lobHMKey = 0;
+    private WeakHashMap lobRefrences = null;
 
 	//////////////////////////////////////////////////////////
 	// STATE (copied to new nested connections, but nesting
@@ -2901,14 +2904,17 @@
 		//free all the lob resources in the HashMap
 		//initialize the locator value to 0 and
 		//the hash table object to null.
-		HashMap map = rootConnection.lobHashMap;
+		Map map = rootConnection.lobRefrences;
 		if (map != null) {
-            Iterator it = map.values().iterator();
+            Iterator it = map.keySet().iterator();
             while (it.hasNext()) {
                 ((EngineLOB)it.next()).free();
 			}
 			map.clear();
 		}
+        if (rootConnection.lobHashMap != null) {
+            rootConnection.lobHashMap.clear();
+        }
 	}
 
 	/**
@@ -2939,6 +2945,18 @@
                 return newKey;
 	}
 
+    /**
+     * Adds an entry of the lob in WeakHashMap. These entries are used
+     * for cleanup during commit/rollback or close.
+     * @param lobReference LOB Object
+     */
+    public void addLOBRefrence (Object lobReference) {
+        if (rootConnection.lobRefrences == null) {
+            rootConnection.lobRefrences = new WeakHashMap ();
+        }
+        rootConnection.lobRefrences.put(lobReference, null);
+    }
+    
 	/**
 	* Return the Hash Map in the root connection
 	* @return the HashMap that contains the locator to LOB object mapping
