From 4b66f83a5bef5c03463573ccb6ebb40b48209a9a Mon Sep 17 00:00:00 2001 From: Andrea Richiardi Date: Thu, 23 Jun 2016 15:34:17 -0700 Subject: [PATCH] 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 https://github.com/adzerk-oss/boot-test/issues/26 --- boot/pod/src/boot/pod.clj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/boot/pod/src/boot/pod.clj b/boot/pod/src/boot/pod.clj index f5da91d7..606a53ed 100644 --- a/boot/pod/src/boot/pod.clj +++ b/boot/pod/src/boot/pod.clj @@ -276,6 +276,11 @@ boot. See #'boot.pod/add-shutdown-hook! for more info." (atom nil)) +(def ^:dynamic *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))) @@ -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)))