Skip to content

Instantly share code, notes, and snippets.

@fbmnds
Created July 3, 2013 18:08
Show Gist options
  • Select an option

  • Save fbmnds/5921134 to your computer and use it in GitHub Desktop.

Select an option

Save fbmnds/5921134 to your computer and use it in GitHub Desktop.
Memory Leak?
(defn lazy-read-csv
"This one has lazily reads from the file and generates the CSV data.
It will leak if the sequence is not fully consumed."
([csv-file]
(let [in-file (io/text-reader csv-file) ;; FB: io/reader
csv-seq (csv/read-csv in-file)
lazy (fn lazy [wrapped]
(lazy-seq
(if-let [s (seq wrapped)]
(cons (first s) (lazy (rest s)))
(.Close in-file))))] ;; FB: .close
(lazy csv-seq))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment