Last active
January 4, 2016 00:49
-
-
Save bhauman/8543809 to your computer and use it in GitHub Desktop.
This runs fine in Chrome. But the channels seem to be accumulating something in Safari Version 6.1 (7537.71) The standard browser for Lion. This code crashes my browser running it quickly up to 1.7G of memory usage.
This also may be a problem in Safari on iOS7. So far I have learned that it's the ->> threading operator. Comp and partial work fine.
This file contains 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
;; in project.clj | |
;; [org.clojure/clojurescript "0.0-2138"] | |
;; [org.clojure/core.async "0.1.267.0-0d7780-alpha"] | |
(ns checking-safari-leak.core | |
(:require | |
[cljs.core.async :as async | |
:refer [<! map< put! chan]]) | |
(:require-macros [cljs.core.async.macros :as m :refer [go alt! go-loop]])) | |
(defn dev-null [in] | |
(go-loop [v (<! in)] | |
(if (nil? v) :closed (recur (<! in))))) | |
(defn has-memory-leak [input-chan] | |
(->> input-chan | |
(map< identity) | |
(map< identity) | |
(map< identity) | |
(map< identity) | |
(map< identity) | |
(map< identity) | |
(map< identity) | |
(map< identity) | |
(map< identity) | |
(map< identity) | |
(map< identity) | |
(map< identity) | |
(map< identity) | |
(map< identity) | |
(map< identity) | |
(map< identity) | |
) | |
) | |
(defn has-memory-leak-as-well [input] | |
(map< identity | |
(map< identity | |
(map< identity | |
(map< identity | |
(map< identity | |
(map< identity | |
(map< identity | |
(map< identity | |
(map< identity | |
(map< identity | |
(map< identity | |
(map< identity | |
(map< identity | |
(map< identity | |
(map< identity | |
(map< identity | |
(map< identity | |
input)))))))))))))))))) | |
(def no-memory-leak | |
(comp | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity) | |
(partial map< identity))) | |
(defn data [] | |
(mapv identity (range 1000))) | |
(def output-data (atom [])) | |
(defn doit [] | |
(let [output-data (atom [])] | |
(add-watch output-data :output-change (fn [_ _ _ n] | |
(set! (.-innerHTML (.getElementById js/document "main-area")) | |
(apply str | |
(map (fn [x] (str "<div> time: " (:time x) "ms </div>")) | |
n))))) | |
(let [input (chan) | |
;; output (no-memory-leak input) | |
output (has-memory-leak input) | |
start-time (.getTime (js/Date.))] | |
(mapv (fn [x] | |
(put! input (data))) | |
(range 12)) | |
(go-loop [] | |
(<! output) | |
(swap! output-data conj { :time (- (.getTime (js/Date.)) start-time) }) | |
(recur))))) | |
(enable-console-print!) | |
(doit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm consistently getting Safari 8 crashes from CLJS and I have no idea where it's coming from. Seems to be some recursive code I have, possibly... or something to do with channels. It's very difficult to debug. Might be this? http://dev.clojure.org/jira/browse/CLJS-910 which may be as a result of this https://bugs.webkit.org/show_bug.cgi?id=139847