To me this looks totally fine, max-key should keep at most two sequences in memory. I don't think there should be any difference between the non-lazy and lazy versions as the depth of cseq is ~500.
The non-lazy version works for me (no heap error) for inputs 1M, 2M, 4M, but for 4M the java process did start to consume very large amount of memory. I did some tests with the original non-lazy cseq and (apply max-key count (map cseq (take 4000000 (iterate inc 1)))) [Free of chunking I think] Running in VisualVM suggests that % of Used Heap is actually very less. So the problem is that GC isn't running often enough, so the JVM has to keep allocating more memory. Running with -Xmx200M -XX:+UseParallelGC, did keep heap upto 200MB and produces results for 4M, 10M (ans=686) w/o any problems. It will consume much CPU and time though. -- 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