Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bmabey/511428 to your computer and use it in GitHub Desktop.
Save bmabey/511428 to your computer and use it in GitHub Desktop.
(ns memory-leak
(:use [lt.map-pipeline]
[clojure.contrib.seq-utils :only [fill-queue]]))
(defonce quit? (atom false))
;; Doesn't leak
@(future (let [dates (repeatedly (fn []
(java.lang.Thread/sleep 1)
(when @quit? (throw (Exception. "quitting!")))
(java.util.Date.)))]
(doseq [date dates] date)))
;; Does leak
(let [dates (repeatedly (fn []
(java.lang.Thread/sleep 1)
(when @quit? (throw (Exception. "quitting!")))
(java.util.Date.)))]
@(future (doseq [date dates] date)))
;; this block of code will quit
(do
(reset! quit? true)
(java.lang.Thread/sleep 1000)
(reset! quit? false))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment