On Sat, Jan 29, 2011 at 5:42 PM, David Steiner
<davidsteiner2...@gmail.com> wrote:
> another question i had: is there a way to destroy java objects in clojure?
> how do i set an object to null, so the garbage collector can do it's thing?

You just discard all references to an object. Clojure's compiler does
something called "locals clearing", which means if you have

(let [a (make-big-expensive-object)
      b (distill-something-small-from a)]
  (do-something-with b))

it outputs bytecode that sets a to null after b has been assigned, and
before the call to do-something-with, because a is never used after
that point.

So, in short, the compiler does what you're asking about for you, so
you don't have to and your local bindings get to be conceptually
immutable.

Just don't reference a anymore once you want it to be garbage collected.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to