I did some experiment on floating point number precision, that's when I bumped into this problem.
It seems that the range() function caused java.lang.OutOfMemory, the same code which runs well on CPython 2.6.6.
I am using Jython 2.5.1:6813, Sep 26 2009, 13:47:54, running on java.1.6.0_23.


Does anybody know why the generator function range() should consume growing memory as the number get bigger (which should not be the case for generator function).
Is this a bug?

>>> sum = 0
>>> for i in range(100000000):
...   sum += 0.00000001
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
java.lang.OutOfMemoryError: Java heap space
        at org.python.core.__builtin__.range(__builtin__.java:926)
        at org.python.core.__builtin__.range(__builtin__.java:934)
        at org.python.core.BuiltinFunctions.__call__(__builtin__.java:54)
        at org.python.core.PyObject.__call__(PyObject.java:401)
        at org.python.pycode._pyx18.f$0(<stdin>:1)
        at org.python.pycode._pyx18.call_function(<stdin>)
        at org.python.core.PyTableCode.call(PyTableCode.java:165)
        at org.python.core.PyCode.call(PyCode.java:18)
        at org.python.core.Py.runCode(Py.java:1204)
        at org.python.core.Py.exec(Py.java:1248)
        at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:181)
        at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:89)
        at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:70)
        at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:46)
        at org.python.util.InteractiveConsole.push(InteractiveConsole.java:110)
        at org.python.util.InteractiveConsole.interact(InteractiveConsole.java:90)
        at org.python.util.jython.run(jython.java:316)
        at org.python.util.jython.main(jython.java:129)

java.lang.OutOfMemoryError: java.lang.OutOfMemoryError: Java heap space



Execution of the same code in cpython 2.6.6, windows environment:
>>> sum = 0
>>> for i in range(100000000):
...   sum += 0.00000001
...
>>> sum
1.0000000022898672
>>>


---
daniel baktiar
http://savinggaia.tritiumapps.com - saving the planet is everyone's business!