I think I have found a memory leak in clara when calling mk-session
. I have been trying to find a memory leak in one of our services. I eventually found that the leak was from mk-session. This service creates lots of rules dynamically so initially I assumed it was that. I saw the :cache
option in mk-session and thought that we were probably caching all those dynamically created rules, however turning off the cache did not help. I eventually created this minimal code to reproduce the leak. With cache false this leaks, with cache true it doesn't, but when adding in dynamically created rules the cache true also leaks, even after calling clear-session-cache!
(ns mem-leak
(:require [clara.rules :refer [mk-session defquery]]))
(defquery get-status [:?status] [?result <- :status [{status :status}] (= status ?status)])
(defquery get-all-status [] [?result <- :status])
(doseq [i (range 10000)]
(mk-session 'mem-leak
:cache false))
Good finding! Have you created an issue in the clara-rules github repo? https://github.com/cerner/clara-rules/issues
I haven't yet, I'm still busy digging into it, going to create the issue soon
Is this is the Clojure side or the clojurescript side? My gut says clojure, but i just wanted to make sure
clojure
I didn't end up finding anything else useful, so I have just created the ticket https://github.com/cerner/clara-rules/issues/468
At first blush, my mind goes to the nature of mk-session
. Its usage of eval
generates classes on the fly, and i have to wonder if those classes are unable to be freed for some reasonβ¦.
I will have to find time to look into this