File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clojure Garbage Collection

 
Sunderam Goplalan
Ranch Hand
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume Clojure has something similar to GC in Java. If so, how do the GC algorithms used by Java compare with those of Clojure? Immutability is a good thing in the recent languages
such as Clojure and Scala. Often I become concerned with how those languages manage Memory and GC.

How does the user response time compare between Java and Clojure?
 
Carles Gasques
Ranch Hand
Posts: 199
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I understand that Clojure doesn't have a different GC algorithm since it runs in JVM, like Scala, Groovy and others.
Is the JVM that you use that could have different GC algorithms (SAPJVM, JRockit, Apache Harmony, etc).

But seems that some constructs in Clojure, for example persistent collections, tend to be long living objects;
this objects survive the partial garbage collections and only be collected when full GC runs.

If so much work is left to the full GC then could lead to JVM freezing episodes.
The usual workaround to this scenario is enable concurrent GC with a drawback on JVM performance.


Best regards,
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clojure as a JVM language leverages the GC that it is already used by the Java programming language.
You can even use any profiler you have. Just launch the VisualVM tool that is included in the SDK and see how your Clojure program is running.

When it comes to good memory management, Clojure doesn't blindly copy thing. It does it in a more smart way.
For example (conj x y) will return a new collection, that it is true; but it shares the content of the the old one. This is really fast and efficient.
 
norman richards
Author
Ranch Hand
Posts: 367
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd also point out that Clojure aggressively clears local variables when it can so that things can be garbage collected as soon as possible.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic