Thanks for the reply, Gary. Indeed, reflection is a better solution in this scenario.
On a closer look, those ephemeral classes are loaded by "clojure.lang.DynamicClassLoader", each with a retained size of 2,576 bytes, and is only referred to with soft/weak references from GC roots. So, not much of a problem. On Monday, January 12, 2015 at 6:51:48 PM UTC-5, Gary Trakhman wrote: > > There's no need to use eval when reflection will do. > On Mon, Jan 12, 2015 at 6:45 PM Wei "pw" Peng <write.to...@gmail.com > <javascript:>> wrote: > >> I have a problem with stacking ephemeral dynamically generated classes >> that do not get unloaded, and therefore the host JVM's class count >> constantly increases. >> >> My situation is like this. I have a need in my program to dynamically >> interop with Java (see the example below for the exact meaning of >> "dynamically interop with Java"). I use the following trick to bypass the >> "CompilerException java.lang.RuntimeException: Can't embed object in code, >> maybe print-dup not defined" error: >> >> (def ^:dynamic *hack*) >> >> (let [obj "abc" >> method "replace" >> args [\a \b]] >> (binding [*hack* (atom obj)] >> (eval `(. @*hack* >> ~(symbol method) ~@args)))) >> ;; => "bbc" >> >> This works fine for my purpose---functionally. However, profiling shows >> that the JVM loads more classes over time without unloading. The classes >> that are get loaded have names like "clojure.core$eval12345" (with the >> number constantly growing)., which suggests that the above code may be the >> culprit. >> >> Profiling also suggests that my program do not have other memory leak >> problem besides this class leak problem---the heap consumption is flat with >> repeated job. It is the non-heap memory usage that is associated with class >> loading that keeps on growing. >> >> Any suggestion on how to resolve this is appreciated. >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clo...@googlegroups.com >> <javascript:> >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+u...@googlegroups.com <javascript:> >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en >> --- >> You received this message because you are subscribed to the Google Groups >> "Clojure" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+u...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.