Aladdin - Scala Bugtracking
[#1116] project: api priority: medium category: bug
submitter assigned to status date submitted
Nikolay Sean fixed 2007-05-20 15:24:19.0
subject [contrib #483] symbols are not garbage collected
code
===
while (true) {
    new Symbol(String.valueOf("ssssssdfsdfsdfsfdsfdsdfsdfsdf" + i)).intern
}
===

Execute with JAVA_OPTS="-Xmx10m", you will get OOME.

===
Index: Symbol.scala
===================================================================
--- Symbol.scala        (revision 11086)
+++ Symbol.scala        (working copy)
@@ -13,7 +13,7 @@
 
 import scala.collection.jcl
 
-private[scala] object internedSymbols extends jcl.HashMap[String, ref.WeakReference[Symbol]]
+private[scala] object internedSymbols extends jcl.WeakHashMap[Symbol, ref.WeakReference[Symbol]]
 
 /** <p>
  *    Instances of <code>Symbol</code> can be created easily with
@@ -47,10 +47,10 @@
    *
    *  @return the unique reference to this symbol.
    */
-  def intern: Symbol = synchronized {
-    internedSymbols.get(name).map(.get).getOrElse(None) match {
+  def intern: Symbol = internedSymbols.synchronized {
+    internedSymbols.get(this).map(.get).getOrElse(None) match {
     case Some(sym) => sym 
     case _ =>
-      internedSymbols(name) = new ref.WeakReference(this); this
+      internedSymbols(this) = new ref.WeakReference(this); this
   } } 
 }
===

Also added proper synchronization.
what happened
what expected
[back to overview]
Changes of this bug report
Nikolay  edited on  2007-05-20 15:28:08.0
The Symbol saga contibues
Sean  edited on  2007-05-21 13:02:03.0
patch accepted