以下代码将导致 OOME
(require '[clojure.core.async :refer [chan close! <! pub sub unsub go timeout]])
(def p* (chan))
(def p (pub p* :topic))
(go
(loop []
(let [s (chan)
 odat (rand-int Integer/MAX_VALUE)]
(sub p t s)
(<! (timeout 10))
(unsub p t s)
(close! s)
(recur))))
(It grows slowly: to see the OOME in a reasonable amount of time, either give JVM very small
memory like 64m, or remove the timeout step.)
I tried to profile the code, and the reason seems to be that even though I
unsubed the channel from the port, something is still retained which causes
the heap to be used up.