Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doesn't Clojure consume too much perm-gen space?

I'm new to Cojure, but I read that when using AOT compilation a class is generated for each function. Wouldn't that mean a whole lot of classes that consume perm-gen space? Aren't there any issues with that? What about when AOT compilation is not used, but bytecode is generated on the fly?

like image 675
cretzel Avatar asked Feb 23 '11 08:02

cretzel


1 Answers

Well, I think it doesn't matter if the class is loaded from disk or from memory, wrt PermGen space.

However, notice that the problem may not be as bad as you think: each function is compiled once. Especially, anonymous functions which you can see here or there, generated "on the fly" are only compiled once, and each invocation of them just leads to the creation of new instances of those classes (an instance is needed to store the lexical context).

So the following code leads to the creation of two classes (one for create-fn, one for lambda-fn), whatever the number of calls to create-fn will be at runtime:

(defn create-fn [n] (fn lambda-fn [x] (add n x)))

like image 185
Laurent Petit Avatar answered Oct 09 '22 12:10

Laurent Petit