The problem of correctly handling large lazy sequences so they don't blow
up in memory came up at work this week.
I thought I would try to explain the following simple case to our Monday
afternoon study group, and I realized I don't understand it 100%:
(def n 1e8)
(let [s1 (range n)
s2 (map identity s1)]
(count s2))
;;=> 100000000
(let [s1 (range n)
s2 (map identity s1)]
(count s1))
;;=> GC overhead limit exceeded
For the first case, I get that in consuming s2, elements of both s1 and s2
are consumed and garbage-collected; and that in the second case, clearly s1
can't be released as it's consumed because s2 might still need it (even
though we never realize s2). My question is, as s1 is consumed in the
second case, how does it "know" that s2 still holds a reference to it, and
that it therefore should keep the realized values? What is the relevant
difference between these two examples? And where in the Clojure/core code
are the relevant details?
Thanks in advance!
John
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.