On Feb 2, 1:41 pm, Paul Barry <pauljbar...@gmail.com> wrote:
> Ketih,
>
> I think what you have done, at least at the JVM level, is create 100,000
> lists, with basically each list containing an element and a pointer to the
> next element.  Because one list points to the next, none of them can be
> garbage collected.  It seems to me that this would be roughly equivalent to
> one list with 100,000 elements, in terms of memory usage.  In your map
> example, the memory usage is 52 * 100,000 bytes, so that's about 5MB.  How
> much memory is used by the equivalent Java code?
>
> List l = new ArrayList();
> for(int i = 0; i < 100000; i++) {
>     l.add("x");
>
> }
>
> On Mon, Feb 2, 2009 at 1:06 PM, Keith Bennett <keithrbenn...@gmail.com>wrote:
>
>
>
> > 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