diff options
author | James Iry <james.iry@typesafe.com> | 2013-05-17 14:00:57 -0700 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2013-09-03 18:12:35 -0700 |
commit | a78dddd73c0fb26d9c5ef2af3d592ff5f278b237 (patch) | |
tree | bf0bceedcc60063b7b5a19b459f13f37f6f7f6a6 /src | |
parent | 989c3f85d95a22c95bc7ce936c4bd57ff0608bcd (diff) | |
download | scala-a78dddd73c0fb26d9c5ef2af3d592ff5f278b237.tar.gz scala-a78dddd73c0fb26d9c5ef2af3d592ff5f278b237.tar.bz2 scala-a78dddd73c0fb26d9c5ef2af3d592ff5f278b237.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')
-rw-r--r-- | src/reflect/scala/reflect/internal/SymbolTable.scala | 13 |
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 5ccf81b4b5..6ca8900d7c 100644 --- a/src/reflect/scala/reflect/internal/SymbolTable.scala +++ b/src/reflect/scala/reflect/internal/SymbolTable.scala @@ -302,28 +302,21 @@ abstract class SymbolTable extends macros.Universe } object perRunCaches { - import java.lang.ref.WeakReference import scala.runtime.ScalaRunTime.stringOf 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]()) |