Francis Lavoie <lav.fran...@gmail.com> writes:

> (filter even? (range 10))
>
> What's puzzle me is that past at certain number (10 millions), clojure
> chocks and throw a «java.lang.OutOfMemoryError: Java heap space»,
> 1. Why does it happen?

The JVM puts a limit on the amount of memory that can be used.  This is
usually a good indication that you have memory leak (you're holding onto
data when you shouldn't be).  If in fact you really want to be using
that much memory (as in this case where you're apparently wanting to
produce a list of millions of even numbers) then you'll need to increase
the limit.  You can change the limit by specifying say -Xmx800m as a
command-line argument to the JVM for an 800 MB limit.

This may or may not do the trick.  Python may have a more
memory-efficient format for integer objects.  The question perhaps
should be: do I really need a list of millions of even integers?

Note that you should be able to add as many as you want, as the list is
lazy, so it doesn't have to be all in memory at once:

(reduce + (filter even? (range 10000000)))

> 2. As a beginner, will I have to deal with that kind of error as long
> as I won't understand the inner working of clojure? Like I would waste
> time on pointer management while developing with C!

The heap limit is just something you have to deal with in any JVM
language: Java, JRuby, Jython, Scala -- all of them.  It's nothing
Clojure-specific.  Clojure being on the JVM is a trade off.  The JVM
makes some things (like this) unnecessarily complex but it does give
Clojure a whole heap of other benefits: portability, reuse of existing
Java libraries, speed etc.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to