>From Steve's post
Symbol objects are subject to garbage collection, but the "namespace" and
"name" strings that identify them are not. Those strings are "interned" via
the "intern" method on java.lang.String. Once a String is interned, there
exists a single canonical String object that represents it throughout the
remaining lifetime the JVM instance. Any two Symbols of the same namespace
and name will reference those canonical namespace and name strings and will
thus have identical namespaces and names.

      Not interning the Symbols themselves turns out to be important in
Clojure because it allows two Symbols with identical namespace and name to
have different metadata.

      Keyword objects are interned by Clojure and are not garbage collected.
When a Keyword is created, it's placed in a ConcurrentHashMap that maps a
Symbol of the same name and namespace to the Keyword object. In a given JVM
instance, there is at most one Keyword object with a given name and
namespace. Whenever the reader reads a Keyword's text representation, it
returns the unique Keyword object associated with it.

      Here's some repl playing to support this:

             user=> (identical? 'a/b 'a/b)
             false
             user=> (identical? (name 'a/b) (name 'a/b))
             true
             user=> (identical? (namespace 'a/b) (namespace 'a/b))
             true
             user=> (= (quote #^{:tagged true} a/b) (quote a/b))
             true
             user=> (= (meta (quote #^{:tagged true} a/b)) (meta (quote
a/b)))
             false
             user=> (identical? :a/b :a/b)
             true




On Thu, Jun 25, 2009 at 10:25 AM, Rich Claxton <rich.clax...@gmail.com>wrote:

>
> Hello I have just started learning Clojure and functional programming,
> quick question, what happens internally when I do a defn, does this
> create the byte code, or a ref to the function which is stored, as it
> does actually create a function object, I was just wondering about
> memory and GC issues.
>
> Cheers Richard.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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