Hi I'm trying to generate a sequence which corresponds to a breadth-first search of a very wide, deep tree... and I'm hitting memory problems when I go too far along the sequence. Having asked around on the IRC channel and looked here, the number 1 cause of such problems is inadvertently holding onto the head; but I can't see where I'm doing this.
The code is quite simple; here's a version which displays the problem: (def atoms '(a b c)) (defn get-ch [n] (map #(str n %) atoms)) (defn add-ch ([] (apply concat (iterate add-ch atoms))) ([n] (mapcat get-ch n))) (dorun (take 20000000 (add-ch))) And here's another version (which is the one I started out with before getting help from #clojure), which displays the same issue: (def atoms '(a b c)) (defn get-children [n] (map #(str n %) atoms)) (defn add-layer ([] (add-layer atoms)) ([n] (let [child-nodes (mapcat get-children n) ] (lazy-seq (concat n (add-layer child-nodes)))))) (dorun (take 20000000 (add-layer))) Both give me an "OutOfMemoryError Java heap space". I'm running them from the REPL in Eclipse/CounterClockwise, on a Macbook Air. I'm pretty new to Clojure, so after beating my head against this for a day I'm hoping that this is something trivial I'm overlooking. I realise I could up my heap-size to make the issue less likely to occur, but the sequences I ultimately want to process are so vast I don't think this is going to help me... Any suggestions warmly welcomed. Thanks Tom -- 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