I encounter this problem when running a genetic programming algorithm which uses eval.
To illustrate the problem, I narrowed it down to the following code fragment:
(loop []
(do
(eval (list '+ (rand) (rand)))
(recur)))
When I run the code the garbage collector unloads all the created $eval_n classes once from metaspace but on the second garbage collector invocation it hangs.
I use jdk1.8.0_102 with the follwing JVM options: -XX:MetaspaceSize=200m -XX:MaxMetaspaceSize=200m
After a while I get the following error:
CompilerException java.lang.OutOfMemoryError: Metaspace, compiling:(form-init2581690491924993906.clj:1:1)
EDIT: I added a screenshot of visualVM to show the behaviour, when the JVM hangs, the graph is not updated anymore, and it keeps using a full CPU core.
I also tried it using java 7 (without any JMV options), and I encounter the same problem with PermGen.
Any ideas how to avoid this problem?
EDIT:
The problem only occurs when I run it from a leinigen-REPL with eclipse-counterclockwise. If I run the code from a basic command line REPL the problem does not occur!