On Thu, Nov 26, 2009 at 02:50:09PM -0800, David Brown wrote:
>I'm writing some fairly complex code involving lazy sequences. I
>appear to be getting a space leak from what looks like something that
>is still holding a reference to the head of the sequence.
Ok, I found the leak. I guess I'd call it a compiler problem. I
haven't been able to narrow it down any further than the code below
(any simpler, and it doesn't cause the problem).
Basically, the with-open causes the generation of a closure which
captures the value of 'coll', which it hangs onto throughout the
lifetime of the call to 'write-mapping' which is what walks through
the entire collection.
For now, I'll do without the with-open, since in this particular case,
errors are going to be fairly fatal anyway.
Should I file a ticket about this?
I'm running 1.1.0-alpha-SNAPSHOT, 20091113040146, from
build.clojure.org.
David Brown
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(ns leak1)
(import '[java.io FileOutputStream BufferedOutputStream DataOutputStream])
(defn make-name [& _])
(defn make-tmp-name [& _])
(defn store-properties [& _])
(defn write-mapping [& _])
(defn get-codec [& _])
(defn raise[& _])
(def error nil)
;;; The generated code creates a 'fn' class for the body of the
;;; with-open. This class binds several of the names, including
;;; 'coll', which it keeps through the lifetime of the function.
(defn- store-index-file
[index idx props coll]
(let [path (make-name index idx)
tmp-path (make-tmp-name path)
fos (FileOutputStream. tmp-path)
bos (BufferedOutputStream. fos)]
(with-open [dos (DataOutputStream. bos)]
(store-properties dos (assoc props :version "1.0"))
(write-mapping dos (get-codec index) coll)
(.flush bos)
;; Calls fsync to make sure data gets written to disk.
(.force (.getChannel fos) true))
(when-not (.renameTo tmp-path path)
(raise error
(str "Unable to rename pool index file:" tmp-path " to " path)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
--
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