Locals clearing is a compiler optimization that nulls references held by a one-time function after execution, allowing the JVM to reclaim referenced resources sooner. section 2.1.3
The optimization depends on three conditions:
- The function body must be intended to execute only once. section 2.1.3
- Marking a function as ^:once fn* promises the compiler that it will not run again. section 2.1.3
- After execution, compiled references to the lambda can be set to null, reducing the time resources remain reachable. section 2.1.3
A once-only future body
(defmacro future [& body] `(future-call (^{:once true} fn* [] ~@body))) The metadata marks the generated function as one-time execution code, enabling locals clearing. section 2.1.3
