On Jun 24, 12:22 pm, "Stephen C. Gilardi" <squee...@mac.com> wrote: > On Jun 24, 2009, at 11:31 AM, samppi wrote: > > > Are keywords and symbols garbage-collected? If I generated a lot of > > keywords or symbols, put them into a collection, and then removed > > them, would they disappear and free up space? I'm wondering if they're > > similar to Ruby symbols, which are never garbage collected. > > 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.
I'm not sure this is correct. I think recent Sun JVMs can GC unreferenced, interned strings. > 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 principle, this could be fixed by using WeakReference and a few other tricks in the implementation. In practice, it will tend not to matter, since only a small number of distinct keyword objects are likely to be used by a typical system. It does suggest that for the time being you be circumspect about using "(keyword foo)" outside, perhaps, of def-style macros, and particularly where it may be invoked with an open-ended set of values for "foo" originating from user input, I/O, or other sources, and similarly for eval'ing or read'ing strings, files, or other data containing occurrences of ":foo" with an open-ended set of values for "foo". --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---