If the head is retained on a lazy sequence we have a potential memory leak.

I set my JVM memory low, 64mb and ran the following:

user> (defn test1 [coll] (reduce + coll))
#'user/test1
user> (test1 (take 10000000 (iterate inc 0)))
49999995000000
user> 

Now if we do:

user> (defn test2 [coll] [(reduce + coll) (reduce + coll)])
#'user/test2
user> (test2 (take 10000000 (iterate inc 0)))
OutOfMemoryError Java heap space  [trace missing]
user> 

Which OOMs as expected. The question is, why doens't the first example blow 
up? What magics happening?

I would expect coll which is a function argument to be retained by the 
garbage collector and hence blow up.

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to