Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Won't Fix
-
Affects Version/s: 1.1-beta-2
-
Fix Version/s: None
-
Component/s: groovy-jdk
-
Labels:None
-
Patch Submitted:Yes
-
Number of attachments :
Description
//generates an infinite sequence of Fibonacci numbers def fibonacci(Closure yield){ def a=0 def b=1 def temp while(true){ yield(b) temp=a a=b b=a+temp } } //BROKEN: the groovy runtime wants to run Fibonacci to termination, loading values into an array. //this generates an out of memory error, before ever calling the closure once. this.&fibonacci.find{it % 20 == 0}
The proper solution is to use the attached Generator class that can properly invert control using threads, and only generates values on demand. I've also posted this solution at http://docs.codehaus.org/display/GROOVY/Iterator+Tricks for now, but it might be better to put it into the GDK.
Issue Links
- is related to
-
GROOVY-54
Add generator syntax similar to Python's
-
Updated version of Generator.java, always garbage collects correctly every time.