Skip to content

Commit

Permalink
Add boot.pod/*destroy-pod-hook*
Browse files Browse the repository at this point in the history
In order to fix memory leaks in task-local pods, we need a way to execute custom cleaning at pod
destroy time. This was particularly evident when doing `boot watch test` in a resource heavy app.

Fixes adzerk-oss/boot-test#26
  • Loading branch information
arichiardi committed Jun 29, 2016
1 parent e6ea562 commit d36ee42
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions boot/pod/src/boot/pod.clj
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@
boot. See #'boot.pod/add-shutdown-hook! for more info."
(atom nil))

(def *destroy-pod-hook*
"Bind this to a 0-arity function in order to perform additional
cleanup."
identity)

(defn set-pods! [x] (alter-var-root #'pods (constantly x)))
(defn set-data! [x] (alter-var-root #'data (constantly x)))
(defn set-pod-id! [x] (alter-var-root #'pod-id (constantly x)))
Expand Down Expand Up @@ -823,6 +828,7 @@
"Closes open resources held by the pod, making the pod eligible for GC."
[pod]
(when pod
(*destroy-pod-hook*)
(.close pod)
(.. pod getClassLoader close)))

Expand Down

0 comments on commit d36ee42

Please sign in to comment.