[armedbear-cvs] r12281 - trunk/abcl/src/org/armedbear/lisp

Erik Huelsmann ehuelsmann at common-lisp.net
Sun Nov 22 19:11:57 UTC 2009


Author: ehuelsmann
Date: Sun Nov 22 14:11:54 2009
New Revision: 12281

Log:
Fix a memory leak for objects-with-documentation going out of scope,
  by making the documentation hash table a WeakHashMap.


Modified:
   trunk/abcl/src/org/armedbear/lisp/LispObject.java

Modified: trunk/abcl/src/org/armedbear/lisp/LispObject.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/LispObject.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/LispObject.java	Sun Nov 22 14:11:54 2009
@@ -33,6 +33,8 @@
 
 package org.armedbear.lisp;
 
+import java.util.WeakHashMap;
+
 public class LispObject extends Lisp
 {
   public LispObject typeOf()
@@ -587,13 +589,16 @@
     return false;
   }
 
-  private static final EqHashTable documentationHashTable =
-    new EqHashTable(11, NIL, NIL);
+  private static final WeakHashMap<LispObject, LispObject>
+      documentationHashTable = new WeakHashMap<LispObject, LispObject>();
 
   public LispObject getDocumentation(LispObject docType)
 
   {
-    LispObject alist = documentationHashTable.get(this);
+    LispObject alist;
+    synchronized (documentationHashTable) {
+      alist = documentationHashTable.get(this);
+    }
     if (alist != null)
       {
         LispObject entry = assq(docType, alist);
@@ -606,19 +611,21 @@
   public void setDocumentation(LispObject docType, LispObject documentation)
 
   {
-    LispObject alist = documentationHashTable.get(this);
-    if (alist == null)
-      alist = NIL;
-    LispObject entry = assq(docType, alist);
-    if (entry instanceof Cons)
-      {
-        ((Cons)entry).cdr = documentation;
-      }
-    else
-      {
-        alist = alist.push(new Cons(docType, documentation));
-        documentationHashTable.put(this, alist);
-      }
+    synchronized (documentationHashTable) {
+      LispObject alist = documentationHashTable.get(this);
+      if (alist == null)
+        alist = NIL;
+      LispObject entry = assq(docType, alist);
+      if (entry instanceof Cons)
+        {
+          ((Cons)entry).cdr = documentation;
+        }
+      else
+        {
+          alist = alist.push(new Cons(docType, documentation));
+          documentationHashTable.put(this, alist);
+        }
+    }
   }
 
   public LispObject getPropertyList()




More information about the armedbear-cvs mailing list