[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

java and c#

hi there
  there are six garbage algorithms in java and i came to know that C# uses mark and compact garbage collection algorithm. now my question is which garbage algorithm java uses among those six or its like the selection of garbage algm depends on the code..... and my next question is there only one(mark and compact) gc algorithm in C# or it has more like java....
3 Solutions
On my knowledge only one algorith is used, and you may see it's description here:

Well, I don't know Java, but can tell you how it happens in .Net :)

Yes, algorithm is only one. But GC has three modes:
- Server - CLR runs several garbage collections (one per proc) (this also involves several heaps)
- Workstation - one, not concurrent garbage collection
-Concurrent - garbage collection is one, but it goes in concurrent mode (so program do not freezes)

Good luck in learning .Net
Java doesn't have a standard garbage collection algorithm. The JVM Specification [1] explicitly omits a prescriptive garbage collection algorithm to allow those implementing a JVM the freedom to use the most appropriate for the implementation's platform. I don't know where your belief 'six garbage algorithms in java' comes from but six JVMs might employ six different algorithms, so perhaps this is its origin?

Together, the Java Language Specification [2] and the JVM Specification describe in detail when an object becomes eligible for garbage collection, but neither enforce a collection algorithm.

It may be that a specific JVM implementation documents how it achieves garbage collection but as a programmer it is surely better to write code with specification in mind, rather than an individual implementation. If it is memory efficient code that you are concerned about then perhaps the Java Performance book [3] will help.

Sorry, I don't know how C# does it, but I guess there are fewer CLR implementations than JVM implementations so perhaps there is some standardisation?

Hope this helps.

[1] http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html
[2] http://java.sun.com/docs/books/jls/second_edition/html/execution.doc.html
[3] http://java.sun.com/docs/books/performance/1st_edition/html/JPAppGC.fm.html

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now