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....
gobicseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

anarki_jimbelSenior DeveloperCommented:
On my knowledge only one algorith is used, and you may see it's description here:

http://msdn.microsoft.com/en-us/magazine/bb985010.aspx
0
lazyberezovskyCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sailingbyeCommented:
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.

References:
[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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.