All -

I'm curious to know how to minimize memory consumption in Clojure for
large lists.  I did the following test in repl:
(def d ())
(dotimes [_ 100000] (def d (cons "x" d)))

Then, I used VisualVM, an awesome free profiling tool (https://
visualvm.dev.java.net/) to examine the results.  It indicated that the
number of clojure.lang.PersistentList instances increased by 100,000.
Each instance appeared to consume 48 bytes (not including the actual
value, but only its reference, I presume).  I don't think any were
eligible for garbage collection, because I initiated gc several times,
and they were not removed.  (I know that gc() is not deterministic,
but am pretty sure that they would have been removed. Feel free to
correct me.)

Thinking that maybe the special functions like map did some magic to
save memory, I tried this:

(def a (map #(* 2 %) (range 100000)))

The result was 100,000 clojure.lang.LazyCons objects, each of which
consuming 52 bytes.

Are there alternate strategies for building a large sequence that
would consume less memory per element?

Thanks,
Keith

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