Index: generic/tclNamesp.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclNamesp.c,v
retrieving revision 1.31.2.13
diff -u -r1.31.2.13 tclNamesp.c
--- generic/tclNamesp.c	28 Nov 2006 22:20:02 -0000	1.31.2.13
+++ generic/tclNamesp.c	8 Feb 2007 21:32:23 -0000
@@ -299,6 +299,7 @@
     }
 
     nsPtr->activationCount++;
+    nsPtr->refCount++;
     framePtr->nsPtr = nsPtr;
     framePtr->isProcCallFrame = isProcCallFrame;
     framePtr->objc = 0;
@@ -384,6 +385,10 @@
 	    && (nsPtr->activationCount == 0)) {
         Tcl_DeleteNamespace((Tcl_Namespace *) nsPtr);
     }
+    nsPtr->refCount--;
+    if ((nsPtr->refCount == 0) && (nsPtr->flags & NS_DEAD)) {
+	NamespaceFree(nsPtr);
+    }
     framePtr->nsPtr = NULL;
 }
 
@@ -602,7 +607,7 @@
      * FreeNsNameInternalRep when its refCount reaches 0.
      */
 
-    if (nsPtr->activationCount > 0) {
+    if (0 && nsPtr->activationCount > 0) {
         nsPtr->flags |= NS_DYING;
         if (nsPtr->parentPtr != NULL) {
             entryPtr = Tcl_FindHashEntry(&nsPtr->parentPtr->childTable,
@@ -634,9 +639,12 @@
 	     */
 
             TclDeleteNamespaceVars(nsPtr);
+	    Tcl_InitHashTable(&nsPtr->varTable, TCL_STRING_KEYS);
 	    
             Tcl_DeleteHashTable(&nsPtr->childTable);
+	    Tcl_InitHashTable(&nsPtr->childTable, TCL_STRING_KEYS);
             Tcl_DeleteHashTable(&nsPtr->cmdTable);
+	    Tcl_InitHashTable(&nsPtr->cmdTable, TCL_STRING_KEYS);
 
             /*
              * If the reference count is 0, then discard the namespace.
