Clojure 1.11.4
Clojure 1.11.4 is now available with the following fixes: CLJ-2145 Fix clearing of closed overs in ^:once fns In some cases (see the ticket for details), functions that closed-over bindings in the outer scope were not clearing the use of those bindings in the inner function scope, which could potentially cause head-holding. These closed-overs are now clearable for garbage collection. CLJ-2317 recur to head of :once fn cancels once The :once function metadata is a hint to the compiler that a function will only be run once, and thus closed-over fields may be cleared. It is nonsensical to recur to the head of a :once fn (as that implies running it more than once), but this situation can arise through the use of macros that apply wrap arbitrary bodies in :once fns. In this case closed-over fields would sometimes be cleared prior to the recur. Now, use of recur to the head of a :once fn will ignore the :once flag and closed-over fields will not be cleared in the fn. Clearing of other local fields (not closed-over) is unchanged.

Clojure 1.11.4 has been released, bringing two significant fixes that address issues related to garbage collection and the behavior of functions marked with the `:once` metadata. These improvements are crucial for developers working with Clojure, as they help prevent memory leaks and ensure the correct handling of recursive functions.
The first fix, CLJ-2145, resolves a problem with the clearing of closed-over bindings in `^:once` functions. In certain scenarios, functions that closed-over bindings in the outer scope were not properly clearing the use of those bindings in the inner function scope. This could lead to head-holding, a situation where memory cannot be garbage collected because the inner function still references the outer bindings. By addressing this issue, Clojure 1.11.4 ensures that these closed-overs are now clearable for garbage collection, preventing such memory leaks.
The second fix, CLJ-2317, tackles a situation where using `recur` to return to the head of a `:once` function would inadvertently clear closed-over fields. The `:once` metadata is a hint to the compiler that a function will only be run once, allowing it to clear closed-over fields. However, it is nonsensical to `recur` to the head of a `:once` function, as this implies running it more than once. This scenario can arise through the use of macros that wrap arbitrary bodies in `:once` functions. In previous versions, using `recur` in such cases would sometimes clear closed-over fields before the `recur`, leading to unexpected behavior.
In Clojure 1.11.4, using `recur` to the head of a `:once` function now ignores the `:once` flag, ensuring that closed-over fields are not cleared within the function. This change preserves the intended behavior of `:once` functions while avoiding unintended side effects. The clearing of other local fields, which are not closed-over, remains unchanged.
These fixes in Clojure 1.11.4 are essential for developers who rely on the language's garbage collection features and the `:once` metadata for optimizing performance. By resolving these issues, the new version provides a more stable and predictable runtime environment, reducing the likelihood of memory leaks and unexpected behavior in recursive functions. As Clojure continues to evolve, these improvements reinforce its reputation as a powerful and efficient functional programming language.










