Consider this code snippet which calculates the delta time since the last frame:
(defn game-loop [window game] (let [last-frame (atom (GLFW/glfwGetTime))] (while (not (GLFW/glfwWindowShouldClose window)) (let [now (GLFW/glfwGetTime) delta (- now @last-frame)] (reset! last-frame now) My understanding of an atom is that when I replace it's value, the old value will be left for garbage collection (unless referenced elsewhere). That would mean that I'm producing garbage at 60 frames a second.
If this is correct, is there a way to avoid that? Is there a way to write to a variable without writing Java code? Or is there some neat trick to calculate delta time without using an atom?
volatile!(clojuredocs.org/clojure.core/volatile!), but it won't make any difference in this particular case.