I'm reading Clojure Programming book by O'Reilly..
I came over an example of head retention. First example retains reference
to d (I presume), so it doesnt get garbage collected:
(let [[t d] (split-with #(< % 12) (range 1e8))]
[(count d) (count t)]);= #<OutOfMemoryError java.lang.OutOfMemoryError:
Java heap space>
While second example doesnt retain it, so it goes with no problem:
(let [[t d] (split-with #(< % 12) (range 1e8))]
[(count t) (count d)]);= [12 99999988]
What I don't get here is what exactly is retained in which case and why. If
I try to return just [(count d)], like this:
(let [[t d] (split-with #(< % 12) (range 1e8))]
[(count d)])
- it seems to create same memory problem. Why is that?
Further, I recall reading that count in every case realizes/evaluates a
sequence. So, i need that clarified.
If I try to return (count t) first, how is that faster/more memory
efficient then if I dont return it at all? And what & why gets retained in
which case?
--
--
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/groups/opt_out.