Unused destructured local not cleared, causes memory leak

Description

Clojure currently doesn't clear unused locals. This is problematic as some form of destructuring can generate unused/unusable locals that the compiler cannot clear and thus can cause head retention:

Here's a macroexpansion that exposes this issue:

Cause: The first two bindings of a and b will hold onto the head of c since they are never used and not accessible from the loop body they cannot be cleared.

Approach: Track whether local bindings are used. After evaluating the binding expression, if the local binding is not used and can be cleared, then pop the result rather than storing it.

Patch: 0001-CLJ-1744-clear-unused-locals-v2.patch

Screened by: Alex Miller

Environment

None

Attachments

2

Activity

Show:

Nicola Mometto December 15, 2015 at 5:47 PM

While investigating an unrelated memory leak on core.async (ASYNC-138) I discovered that this bug also affects code inside a `go` macro, since it often emits unreachable bindings

import November 18, 2015 at 12:12 PM

Comment made by: jarohen

FYI - we've hit this as a memory leak in our production system:

The work-around in our case is easy enough - removing the unused symbol - but, given we assumed including an unused symbol would be a no-op, it did take us a while to find!

Cheers,

James

Michael Blume June 3, 2015 at 6:57 PM

Nice =)

Completed

Details

Assignee

Reporter

Approval

Ok

Patch

Code

Priority

Fix versions

Created June 3, 2015 at 4:16 PM
Updated August 19, 2016 at 5:34 PM
Resolved August 19, 2016 at 5:34 PM