On Sun, Jul 3, 2011 at 2:38 AM, Christophe Grand <christo...@cgrand.net> wrote:
> Creating sentinel values a bit like (Object.) but easier on the eye when
> debugging.

One problem with that is that, at least with the default HotSpot JVM
settings, symbols (and keywords) clog up permgen space and generating
them at runtime eventually leads to OOME as a result. Objects created
with (Object.) are garbage collected normally. They also only take up
8 bytes, whereas a novel Symbol takes up 60 bytes plus two per
character in the symbol name = ~70 minimum for a typical gensym.

(The math is from noting these fields of clojure.lang.Symbol: ns name
hash meta. 8 byte object header plus four for each of these values is
24; ns may point to a string but it will be shared with other Symbols
and the default meta value is null, so those do not add any more
memory usage. But the name string does. It's interned, but it's also
got a unique numeric suffix (gensym names seem to try to be globally
unique, not just unique within the namespace, and usually have no
namespace anyway) so it will not be shared. That's another 8 bytes for
the String object header and String has four more fields: a char
array, offset, count, and hash. The latter three are ints, so another
12 bytes down the tubes and the array pointer is another 4, to which
we can add the array's 8 byte object header, length field, and
contents:

symbol
  object header      8
  ns                 4
  name               4
    object header    8
    content          4
      object header  8
      length         4
      cells          n*2
    hash             4
    offset           4
    count            4
  hash               4
  meta               4
total                60 + n*2

And all of that is going in permgen.)

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

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