public
Created

A bug in fine-grained locals clearing in Clojure 1.5?

  • Download Gist
locals_clearing.clj
Clojure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
(deftype FinalizeReporter [x]
Object
(finalize [this] (println "Finalizing" x))
clojure.lang.IDeref
(deref [this] x))
 
(defn leaker [n]
(with-open [_ (reify java.io.Closeable (close [this]))]
(let [s (map #(FinalizeReporter. %) (take 10 (iterate inc 0)))]
(when (> n -1)
(try
(->> s
(map #(do (Thread/sleep 100) (System/gc) (println @%)))
dorun))))))
 
ser=> *clojure-version*
{:major 1, :minor 5, :incremental 0, :qualifier nil}
user=> (leaker 10)
0
1
2
3
4
5
6
7
8
9
nil
user=> (System/gc)
Finalizing 9
Finalizing 8
Finalizing 7
Finalizing 6
Finalizing 5
Finalizing 4
Finalizing 3
Finalizing 2
Finalizing 1
Finalizing 0
 
user=> *clojure-version*
{:major 1, :minor 4, :incremental 0, :qualifier nil}
user=> (leaker 10)
0
Finalizing 0
1
Finalizing 1
2
Finalizing 2
3
Finalizing 3
4
Finalizing 4
5
Finalizing 5
6
Finalizing 6
7
Finalizing 7
8
Finalizing 8
9
nil

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.