From de67e153ee74427f98b4ea5c21afa8fb01fe374a Mon Sep 17 00:00:00 2001 From: Aleksandar Pokopec Date: Wed, 2 Jun 2010 16:31:56 +0000 Subject: Partially solves the problem for #3502. This commit reimplements filter for Streams, but does not reimplement map in StreamWithFilter. The problem is that GC can't collect instances of Streams residing on the stack if there are multiple references to the Stream (more than a single one on the stack on which a Stream method is invoked). In the case of a StreamWithFilter, being an inner class, there is always an `$outer` reference to the outer object, so there is little GC can do. Possible solution - change the return type of WithFilter to something else (in TraversableLike) to allow it to return objects that don't have to subclass TraversableLike.WithFilter, and reimplement the withFilter method in Stream to simply call `filter` method - in the case of Streams, `withFilter` has little sense in either case... --- test/files/run/t3502.scala | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test/files/run/t3502.scala (limited to 'test/files/run') diff --git a/test/files/run/t3502.scala b/test/files/run/t3502.scala new file mode 100644 index 0000000000..cc78e54c86 --- /dev/null +++ b/test/files/run/t3502.scala @@ -0,0 +1,24 @@ + + + + + +// ticket #3502 +object Test { + + object GeneratePrimeFactorsLazy extends (Int => List[Int]) { + override def apply(n:Int) = { + val s = Stream.range(2, n / 2).filter(n % _ == 0) + //val s = for (i <- Stream.range(2, n / 2); if n % i == 0) yield i + s.headOption.map(x => x :: apply(n / x)).getOrElse(List(n)) + } + } + + def main(args:Array[String]) { + // a prime number + //val num = 623456789 + val num = 2796203 + assert(GeneratePrimeFactorsLazy(num) == List(num)) + } + +} -- cgit v1.2.3