Indirect function calls through Var instances fail to clear locals


  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: Release 1.4
  • Fix Version/s: Release 1.6
  • Component/s: None
  • Labels:
  • Environment:
    Probably all, but observed on Ubuntu 12.04, OpenJDK 6
  • Patch:
  • Approval:


If you make a function call indirectly by invoking a Var object (which derefs itself and invokes the result), the invocation parameters remain in the thread's local stack for the duration of the function call, even though they are needed only long enough to be passed into the deref'd function. As a result, passing a lazy seq into a function invoked in its Var form may run out of memory if the seq is forced inside that function. For example:

(defn total [xs] (reduce + 0 xs))
(total (range 1000000000))   ; this works, though takes a while
(#'total (range 1000000000)) ; this dies with out of memory error

Solution: Similar to RestFn, wrap each argN in Var inside a Util.ret1(argN, argN = null).

Patch: var-clear-locals-patch-v2.diff

Screened by: Alex Miller

  1. var-clear-locals.diff
    29/Nov/12 2:57 PM
    19 kB
    Timothy Baldridge
  2. var-clear-locals-patch-v2.diff
    22/Oct/13 9:13 AM
    18 kB
    Alex Miller
  3. var-clear-locals-patch-v2.txt
    05/Sep/13 6:18 PM
    18 kB
    Andy Fingerhut



Vote (0)
Watch (2)


  • Created: