There's no need to use eval when reflection will do.
On Mon, Jan 12, 2015 at 6:45 PM Wei "pw" Peng <[email protected]>
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 [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> 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 [email protected].
> 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 [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to