diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2009-09-28 16:10:38 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2009-09-28 16:10:38 +0000 |
commit | 449f2a7473cb2c390981c1dead2da86a5129feae (patch) | |
tree | 461ea0311ba7e4e3745618ee00dfcd972177d304 /test/files | |
parent | 4231751ecf81819f9e973df817c884158014fa51 (diff) | |
download | scala-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')
-rw-r--r-- | test/files/run/lazy-leaks.scala | 18 |
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 + } +} |