File: t8946.scala

package info (click to toggle)
scala 2.11.8-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 61,060 kB
  • ctags: 3,923
  • sloc: java: 13,251; xml: 3,214; sh: 1,553; python: 756; makefile: 40; awk: 36; ansic: 6
file content (29 lines) | stat: -rw-r--r-- 829 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Tests to assert that references to threads are not strongly held when scala-reflection is used inside of them.
object Test {
  import scala.ref.WeakReference

  def forceGc() = {
    var obj = new Object
    val ref = new WeakReference(obj)
    obj = null;
    while(ref.get.nonEmpty)
      Array.ofDim[Byte](16 * 1024 * 1024)
  }

  def main(args: Array[String]): Unit = {
    val threads = for (i <- (1 to 16)) yield {
      val t = new Thread {
        override def run(): Unit = {
          import reflect.runtime.universe._
          typeOf[List[String]] <:< typeOf[Seq[_]]
        }
      }
      t.start()
      t.join()
      WeakReference(t)
    }
    forceGc()
    val nonGCdThreads = threads.filter(_.get.nonEmpty).length
    assert(nonGCdThreads == 0, s"${nonGCdThreads} threads were retained; expected 0.")
  }
}