Skip to content

Commit d36ee42

Browse files
committed
Add boot.pod/*destroy-pod-hook*
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
1 parent e6ea562 commit d36ee42

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

boot/pod/src/boot/pod.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@
276276
boot. See #'boot.pod/add-shutdown-hook! for more info."
277277
(atom nil))
278278

279+
(def *destroy-pod-hook*
280+
"Bind this to a 0-arity function in order to perform additional
281+
cleanup."
282+
identity)
283+
279284
(defn set-pods! [x] (alter-var-root #'pods (constantly x)))
280285
(defn set-data! [x] (alter-var-root #'data (constantly x)))
281286
(defn set-pod-id! [x] (alter-var-root #'pod-id (constantly x)))
@@ -823,6 +828,7 @@
823828
"Closes open resources held by the pod, making the pod eligible for GC."
824829
[pod]
825830
(when pod
831+
(*destroy-pod-hook*)
826832
(.close pod)
827833
(.. pod getClassLoader close)))
828834

0 commit comments

Comments
 (0)