Created
March 5, 2013 05:43
-
-
Save w01fe/5088279 to your computer and use it in GitHub Desktop.
A bug in fine-grained locals clearing in Clojure 1.5?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment