Skip to content

Comment on Clojure: Genetic Mona Lisa problem in 250 beautiful lines

Comments

"Lambdas are not garbage collected.

Yes. That means lambdas can be the cause of memory leaks.

As described by Charles Nutter, each lambda in Clojure is an anonymous class in Java. The problem is that classes are never garbage collected. They reside in a special place called the PermGen."

I know very little about Clojure, but that seems like a huge problem for Clojure, and other functional-ish JVM languages. Is it?

I've used Rhino (JavaScript on JVM) extensively, and I don't think it suffers from this.

He means the compiled code of a lambda can't be GC'ed. He was creating new functions inside of an eval.

The individual closures created as code executes are GC'ed like everything else.

Since eval is rather specialized, and everyone recommends it be avoided in "normal" code, this is not a major problem.

Plus, it is fixed.

"As of r1232, lambdas created in eval can be GCed."

- Comment from cgrand at the bottom of the article.

Honestly, the JVM is pretty crappy right now for functional language support. A lot of stuff has to be implemented by hand in either the compiler or the program itself. Several features in Clojure take the latter track at the moment.

I advocate tracking down people from Sun and asking them in a personable, friendly tone of voice to please fix this kind of problem. On their front lawns.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.