Skip to content

Commit d71fea5

Browse files
committed
Null out owning state of TypeVar after instantiation
After setting the `inst` field of a TypeVar, the owningState is no longer needed. Null it out in order to avoid a memory leak (TypeStates refer to constraints and error logs and error logs can refer to contexts via unforced diagnostic messages).
1 parent 76df105 commit d71fea5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3175,7 +3175,13 @@ object Types {
31753175
final class TypeVar(val origin: TypeParamRef, creatorState: TyperState, val bindingTree: untpd.Tree, val owner: Symbol) extends CachedProxyType with ValueType {
31763176

31773177
/** The permanent instance type of the variable, or NoType is none is given yet */
3178-
private[core] var inst: Type = NoType
3178+
private[this] var myInst: Type = NoType
3179+
3180+
private[core] def inst = myInst
3181+
private[core] def inst_=(tp: Type) = {
3182+
myInst = tp
3183+
if (tp.exists) owningState = null // no longer needed; null out to avoid a memory leak
3184+
}
31793185

31803186
/** The state owning the variable. This is at first `creatorState`, but it can
31813187
* be changed to an enclosing state on a commit.

0 commit comments

Comments
 (0)