Monday, December 16, 2013

head retention

if you hold a reference to the head of a sequence, you prevent VM from GC any elements in the sequence.
e.g.
(let [[t d] (split-with #(< % 12) (range 1e8))]  [(count d) (count t)])
- because, when counting d, t is retained, and none of the elements are GC-able.
However, in
(let [[t d] (split-with #(< % 12) (range 1e8))] [(count t) (count d)])

- because after counting t, when you count d, numbers(elements) are are already counted can be GC collected.

No comments:

Post a Comment