2010/11/23 DarkMagus <z...@isa-software.com> > > % (def x (iterate inc 1)) > % (take 1 (drop 100000000 x)) > > Can someone, please, explain to me why the above code crashes with an > out of memory exception? it works fine when the drop number is small. > But as I increase the drop number clojure starts getting slower and > slower until the point where I receive the memory exception and REPL > just disappears from my screen. >
Global variable x retains a reference to the head of the seq iterate creates. So the whole seq is kept in memory, until there isn't enough memory anymore. try (def x #(iterate inc 1)) (take 1 (drop 1000000000 (x)) if you do not want to blow up the memory. HTH, -- Laurent -- 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