Closed
Description
class LeakMe {
def bar(a: Int => Int) = a(2)
val s = 1
def noCapture = bar{x => println(x); x}
def yesCapture = bar{x => println(x + s); x}
}
In this class, the lambda inside noCapture
does not need the LeakMe
instance and can be made a static method. It is made into a private method instead, implicitly capturing LeakMe.this
Unlike this, in scalac-2.11 the anonymous class created for noCapture
does not capture LeakMe
.