> The problems
>
> I can't use map as in (map println (file-seq (java.io.File.
> "/DirectoryWithMillionsOfFiles"))). Map realizes the sequence.

You can't use `map` because `map` will return a sequence of the same
size and that can blow your heap.

> I can't use for as in (for [x (files)] (println x)). For realizes the
> sequence.
> I can't use dorun because even though dorun doesn't realize the sequence, it
> can't execute a function on every element.
> I can't use loop recur because it also realizes the sequence: (loop [a
> (files) b (first a)] (println b) (recur (rest a) (first a)))

Going by the examples here, it seems you are holding on the head by
binding the while file-seq to a var called `files`. That is the
problem.

Take a look at my loop-recur example. You'll see that I create a
temporary binding that gets reduced in size every time I recur. So in
that example, I am not holding on to the head anywhere and the files
that I have printed will get GCd quickly without blowing up.

To repeat, the problem is in holding on to the head (ie. the whole
sequence) and if you process every item and throw away items from the
seq there shouldn't be any problem.

Regards,
BG

-- 
Baishampayan Ghose
b.ghose at gmail.com

-- 
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