Hi, learning clojure and came across some code discussing swing and a code
for a flipper as below
(defn new-flipper []
(agent {:total 0, :heads 0,
:running false,
:random (java.util.Random.)}))
(defn calculate [state]
(if (:running state)
(do (send *agent* calculate)
(assoc state
:total (inc (:total state))
:heads (if (.nextBoolean (:random state))
(inc (:heads state))
(:heads state))))
state))
(defn start [state]
(send *agent* calculate)
(assoc state :running true))
(defn stop [state]
(assoc state :running false))
Under 1.2.1 when i run using
(def flipper (new-flipper))
(send flipper start)
all seems fine and the counts increase and can be viewed by deref'ing
flipper.
But under 1.3 and a build of 1.4 from a few days ago it quickly grinds to a
halt and a deref gives the exception below.
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.privateGetPublicMethods(Class.java:2547)
at java.lang.Class.getMethods(Class.java:1410)
at clojure.lang.Reflector.getMethods(Reflector.java:375)
at clojure.lang.Reflector.invokeStaticMethod(Reflector.java:224)
at clojure.main$repl_caught.invoke(main.clj:172)
at clojure.main$repl$fn__5972.invoke(main.clj:267)
at clojure.main$repl.doInvoke(main.clj:265)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.main$repl_opt.invoke(main.clj:331)
at clojure.main$main.doInvoke(main.clj:427)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.Var.invoke(Var.java:397)
at clojure.lang.AFn.applyToHelper(AFn.java:159)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.main.main(main.java:37)
Probably my lack of understand, but wasn't expecting and out of memory
given the code.
What's happening ??
Thank
--
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