On Thu, Nov 26, 2009 at 04:00:34PM -0800, David Brown wrote: >For now, I'll do without the with-open, since in this particular case, >errors are going to be fairly fatal anyway.
BTW, I still haven't been able to figure out how to write this function without hanging onto the collection across the call to 'write-mapping'. Any ideas? >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >(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 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