diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-07-12 12:09:54 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-07-12 12:09:54 -0700 |
commit | 2247593472031fd9712b652bab0b978a788e46ef (patch) | |
tree | 580d7404c3996f4d0fa2ccf7c7a8f4cdb2236bc9 /test/files | |
parent | 1035bb3916474d5beb955dde23e6ed45be8cfd05 (diff) | |
parent | 48c677ceb3177d93e700b399c00af6b8bb6419e4 (diff) | |
download | scala-2247593472031fd9712b652bab0b978a788e46ef.tar.gz scala-2247593472031fd9712b652bab0b978a788e46ef.tar.bz2 scala-2247593472031fd9712b652bab0b978a788e46ef.zip |
Merge pull request #2674 from richdougherty/2.10.x-si7336-try2
SI-7336 Link flatMapped promises to avoid memory leaks
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/t7336.scala | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/files/run/t7336.scala b/test/files/run/t7336.scala new file mode 100644 index 0000000000..ace83f2c1f --- /dev/null +++ b/test/files/run/t7336.scala @@ -0,0 +1,31 @@ +import scala.concurrent.Await +import scala.concurrent.ExecutionContext.Implicits.global +import scala.concurrent.Future +import scala.concurrent.duration.Duration + +/** This test uses recursive calls to Future.flatMap to create arrays whose + * combined size is slightly greater than the JVM heap size. A previous + * implementation of Future.flatMap would retain references to each array, + * resulting in a speedy OutOfMemoryError. Now, each array should be freed soon + * after it is created and the test should complete without problems. + */ +object Test { + def main(args: Array[String]) { + def loop(i: Int, arraySize: Int): Future[Unit] = { + val array = new Array[Byte](arraySize) + Future.successful(i).flatMap { i => + if (i == 0) { + Future.successful(()) + } else { + array.size // Force closure to refer to array + loop(i - 1, arraySize) + } + + } + } + + val arraySize = 1000000 + val tooManyArrays = (Runtime.getRuntime().totalMemory() / arraySize).toInt + 1 + Await.ready(loop(tooManyArrays, arraySize), Duration.Inf) + } +}
\ No newline at end of file |