summaryrefslogtreecommitdiff
path: root/test/files/run/lazy-leaks.scala
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2009-09-28 16:10:38 +0000
committerIulian Dragos <jaguarul@gmail.com>2009-09-28 16:10:38 +0000
commit449f2a7473cb2c390981c1dead2da86a5129feae (patch)
tree461ea0311ba7e4e3745618ee00dfcd972177d304 /test/files/run/lazy-leaks.scala
parent4231751ecf81819f9e973df817c884158014fa51 (diff)
downloadscala-449f2a7473cb2c390981c1dead2da86a5129feae.tar.gz
scala-449f2a7473cb2c390981c1dead2da86a5129feae.tar.bz2
scala-449f2a7473cb2c390981c1dead2da86a5129feae.zip
Lazy fields null out fields that are used only ...
Lazy fields null out fields that are used only in their initializer. When the lazy value is forced, it will null out all private fields that are used only by the current lazy value. This should reduce memory leaks, see #720
Diffstat (limited to 'test/files/run/lazy-leaks.scala')
-rw-r--r--test/files/run/lazy-leaks.scala18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/files/run/lazy-leaks.scala b/test/files/run/lazy-leaks.scala
new file mode 100644
index 0000000000..e7073b5b60
--- /dev/null
+++ b/test/files/run/lazy-leaks.scala
@@ -0,0 +1,18 @@
+class Lazy(f: => Int) {
+ lazy val get: Int = f
+}
+
+object Test extends Application
+{
+ val buffer = new scala.collection.mutable.ListBuffer[Lazy]
+
+ // This test requires 4 Mb of RAM if Lazy is discarding thunks
+ // It consumes 4 Gb of RAM if Lazy is not discarding thunks
+
+ for (val idx <- Iterator.range(0, 1024)) {
+ val data = new Array[Int](1024*1024)
+ val lz: Lazy = new Lazy(data.length)
+ buffer += lz
+ lz.get
+ }
+}