On Jan 25, 2009, at 5:13 AM, Christophe Grand wrote:
>
> Zak Wilson a écrit :
>> Thanks, Christophe. It works now, and it's fast.
>>
>> Unfortunately, now I've run in to Nathan's problem. After a few
>> thousand generations, resulting in the creation of about half a
>> million functions it was using over a gig of memory and died with an
>> OutOfMemoryError.
>> I don't
>> know the JVM very well at all. Are there any ways around this? Are
>> techniques that generate a lot of short-lived functions just not
>> practical in Clojure?
>>
> Yes there are a way around this: permgen memory is released when the
> classloader is GCed so, if you use a transient classloader, your
> anonymous functions can be collected.
>
I've made it so eval uses an ephemeral classloader in all cases (svn
1232).
Rich
(defn perm-gen
[]
(let [beans (java.lang.management.ManagementFactory/
getMemoryPoolMXBeans)]
(doseq [mx beans]
(when (= "Perm Gen" (.getName mx))
(println (.getUsage mx))))))
(let [fdef `(fn [x#] x#)]
(dotimes [_ 10]
(dotimes [_ 1000]
(eval fdef))
(perm-gen)))
#<MemoryUsage init = 21757952(21248K) used = 27229736(26591K)
committed = 27328512(26688K) max = 88080384(86016K)>
#<MemoryUsage init = 21757952(21248K) used = 14364088(14027K)
committed = 21757952(21248K) max = 88080384(86016K)>
#<MemoryUsage init = 21757952(21248K) used = 19596088(19136K)
committed = 21757952(21248K) max = 88080384(86016K)>
#<MemoryUsage init = 21757952(21248K) used = 24829832(24247K)
committed = 25034752(24448K) max = 88080384(86016K)>
#<MemoryUsage init = 21757952(21248K) used = 11964344(11683K)
committed = 21757952(21248K) max = 88080384(86016K)>
#<MemoryUsage init = 21757952(21248K) used = 17196344(16793K)
committed = 21757952(21248K) max = 88080384(86016K)>
#<MemoryUsage init = 21757952(21248K) used = 22428344(21902K)
committed = 22740992(22208K) max = 88080384(86016K)>
#<MemoryUsage init = 21757952(21248K) used = 9562856(9338K) committed
= 21757952(21248K) max = 88080384(86016K)>
#<MemoryUsage init = 21757952(21248K) used = 14794856(14448K)
committed = 21757952(21248K) max = 88080384(86016K)>
#<MemoryUsage init = 21757952(21248K) used = 20026856(19557K)
committed = 21757952(21248K) max = 88080384(86016K)>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---