From ed7755b781bd1b444d38329cb22eacaa3fc1c005 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 24 Feb 2014 15:37:14 +0100 Subject: Avoid memory leaks on repeated compilation. Several measures: 1. Invalidate classOfId and superIdOfClass in ContextBase after each run. These contain local classes that should become inaccessible. 2. Also clear implicitScope cache that maps types to their implicit scopes after each run. (not sure whether this is needed; it did show up in paths from root, but on second thought this might have been a gc-able cycle. 3. Avoid capturing contexts in lazy annotations. 4. Avoid capturing contexts in functions that compute souceModule and moduleClass 5. Avoid capturing contexts in Unpickler's postReadOp hook. --- src/dotty/tools/dotc/core/SymbolLoaders.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/dotty/tools/dotc/core/SymbolLoaders.scala') diff --git a/src/dotty/tools/dotc/core/SymbolLoaders.scala b/src/dotty/tools/dotc/core/SymbolLoaders.scala index 6161d0e57..2484165f3 100644 --- a/src/dotty/tools/dotc/core/SymbolLoaders.scala +++ b/src/dotty/tools/dotc/core/SymbolLoaders.scala @@ -49,7 +49,7 @@ class SymbolLoaders { modFlags: FlagSet = EmptyFlags, clsFlags: FlagSet = EmptyFlags, scope: Scope = EmptyScope)(implicit ctx: Context): Symbol = { val module = ctx.newModuleSymbol( owner, name.toTermName, modFlags, clsFlags, - (modul, _) => completer.proxy withDecls newScope withSourceModule modul, + (module, _) => completer.proxy withDecls newScope withSourceModule (_ => module), assocFile = completer.sourceFileOrNull) enterNew(owner, module, completer, scope) enterNew(owner, module.moduleClass, completer, scope) @@ -142,8 +142,9 @@ class SymbolLoaders { /** Load contents of a package */ - class PackageLoader(override val sourceModule: TermSymbol, classpath: ClassPath) + class PackageLoader(_sourceModule: TermSymbol, classpath: ClassPath) extends SymbolLoader { + override def sourceModule(implicit ctx: Context) = _sourceModule def description = "package loader " + classpath.name private[core] val preDecls: MutableScope = newScope @@ -242,7 +243,7 @@ class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader { else ctx.newModuleSymbol( rootDenot.owner, rootDenot.name.toTermName, Synthetic, Synthetic, - (module, _) => new NoCompleter() withDecls newScope withSourceModule module) + (module, _) => new NoCompleter() withDecls newScope withSourceModule (_ => module)) .moduleClass.denot.asClass } if (rootDenot is ModuleClass) (linkedDenot, rootDenot) -- cgit v1.2.3