>  I am getting a lot further now, but still running into OutOfMemory
> errors sometimes.  And it is still the case that once I have suffered
> an OutOfMemoryError, they keep coming.  It does feel as if there must
> be some large memory leak in the emacs/lein swank repl.  Is this a
> recognised issue?

The observations that the data structures are non-lazy still apply,
even if you could postpone the problem by increasing the heap size.

As for swank, I do believe it's keeping a history of return values
from previous commands in a variable whose name I forget. At least
that was the case when I was using Common Lisp; I'm not sure if
clojure-swank does the same. A common pitfall was exactly this; large
structures being retained in this history such that one perceived that
memory was apparently leaking.

Anyone know if this is true with clojure-swank?

> The (print "f") is indeed there only for debugging purposes.  I don't
> think it affects the laziness?

Print does not affect the lazyness of its parameter, but it *will*
consume its parameter. Under the assumption that print internally does
not retain a reference to its head, this would not directly lead to
the entire sequence being in memory. However, if you retain the head
of the sequence elsewhere, you will see the same effect.

For example:

(let [s (for [x [1 2 3 4 5 6]]
          (do
            (println (str x " being materialized"))
            x))]
  (println "before first print")
  (println s)
  (println "before second print")
  (println s))

This will yield the output:

before first print
(1 being materialized
2 being materialized
3 being materialized
4 being materialized
5 being materialized
6 being materialized
1 2 3 4 5 6)
before second print
(1 2 3 4 5 6)

So; consuming a lazy data structure while retaining a reference to its
head, will result in memory use similar to that which you may have
expected if the data structure was not lazy to begin with.

-- 
/ Peter Schuller

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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