summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorJames Iry <james.iry@typesafe.com>2013-05-17 14:00:57 -0700
committerJames Iry <james.iry@typesafe.com>2013-06-04 08:19:30 -0700
commitb7e0fd26db0a0aa2c77b5196a18d99ac91fe072c (patch)
tree69ccf27eadf3aa2b228ffecfb8ba4228724d6eae /src/reflect
parent746d85b2e6f8c8dd64016e0b4c0eafe1b808b147 (diff)
downloadscala-b7e0fd26db0a0aa2c77b5196a18d99ac91fe072c.tar.gz
scala-b7e0fd26db0a0aa2c77b5196a18d99ac91fe072c.tar.bz2
scala-b7e0fd26db0a0aa2c77b5196a18d99ac91fe072c.zip
Modify perRunCaches to not leak WeakReferences
perRunCaches was using a HashMap of WeakReferences which meant it would accumulate WeakReferences over time. This commit uses a WeakHashSet instead so that the references are cleaned up.
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/internal/SymbolTable.scala13
1 files changed, 3 insertions, 10 deletions
diff --git a/src/reflect/scala/reflect/internal/SymbolTable.scala b/src/reflect/scala/reflect/internal/SymbolTable.scala
index 7f9811220f..2ae9f81a09 100644
--- a/src/reflect/scala/reflect/internal/SymbolTable.scala
+++ b/src/reflect/scala/reflect/internal/SymbolTable.scala
@@ -307,27 +307,20 @@ abstract class SymbolTable extends macros.Universe
}
object perRunCaches {
- import java.lang.ref.WeakReference
import scala.collection.generic.Clearable
// Weak references so the garbage collector will take care of
// letting us know when a cache is really out of commission.
- private val caches = mutable.HashSet[WeakReference[Clearable]]()
+ private val caches = WeakHashSet[Clearable]()
def recordCache[T <: Clearable](cache: T): T = {
- caches += new WeakReference(cache)
+ caches += cache
cache
}
def clearAll() = {
debuglog("Clearing " + caches.size + " caches.")
- caches foreach { ref =>
- val cache = ref.get()
- if (cache == null)
- caches -= ref
- else
- cache.clear()
- }
+ caches foreach (_.clear)
}
def newWeakMap[K, V]() = recordCache(mutable.WeakHashMap[K, V]())