Try using xrange instead.

The range function is returning a list of 1,000,000 elements, and you're allocating 20 of these. That's enough to start exhausting the heap by exceeding the max heap size, which defaults to 512M. Unlike CPython, you must specify that for JVM languages, perhaps it's a feature, regardless it's what we have to work with. But obviously you don't have anything here that needs for changing that setting (but to be complete, you would set it with something like -J-Xmx1024m)

On Wed, Aug 19, 2009 at 3:53 PM, una_muna <mariash@gmail.com> wrote:

Hello!
I just started to use Jython, so I ask your pardon if I ask something
obviuos.
As an example I have written a simple application using threads:
############################################
#!/usr/bin/jython

import threading
import os, glob

number_of_threads_in_pool = 20
threadPool =[]

class Compute ( threading.Thread ):

     def run ( self ):
       sum = 0
       for i in range (1000000):
           sum += i

for i in range(number_of_threads_in_pool):
        new_thread = Compute()
        new_thread.setDaemon(True)
        threadPool.append(new_thread)
        new_thread.start( )
        print "Thread no." + new_thread.getName() + " is started";
for existing_thread in threadPool:
       existing_thread.join( )
print "Main finished";
############################################
When running it I receive the following error:
############################################
Traceback (most recent call last):
 File
"/home/marias/StarTeamCP/bin/c:/Work/websec/Main/Projects/ct-jython-test/threading.py",
line 460, in _Thread__bootstrap
   self.run()
 File "threadpoolsimple.py", line 24, in run
   sum += i
OutOfMemoryError: java.lang.OutOfMemoryError: Java heap space
############################################
When running with the CPython interpreter everything works fine.
What I'm doing wrong? Why does this error occure? Does python use java's
Integer object to store the numbers? Is there any memory leak?

I use jython 2.5.0, OS - fedora 8.

Thank you.
Maria.
--
View this message in context: http://www.nabble.com/Memory-allocation-tp25052594p25052594.html
Sent from the jython-users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users



--
Jim Baker
jbaker@zyasoft.com