tags:

views:

176

answers:

3

I am wondering what the differences are or if it is the same across both.

+1  A: 

I suppose there is no conceptual difference. Since memory models are slighlty different(for example volative difference), realization may vary.

Andrew_B
Maybe no conceptual difference on a high level (i.e. garbage collection on both platforms has the same function - clean up objects that aren't referenced anymore), but there are a number of different algorithms to do this, so there are major differences in implementation, even between different versions of Sun's JVM, for example.
Jesper
IMHO if you need to worry about how GC works in 99% means you don't need GC at all.
Andrew_B
+2  A: 

This question is not answerable.

Firstly, none of the relevant specifications will say anything about how Java or .net should implement garbage collection. So there is literally no "way that GC is done" in Java or in .net.

Secondly, the details of how GC is implemented differs between the various vendors for Java and .net respectively, and for any vendor the GC may change with each platform, each major version, minor version and even each patch version. On top of that, some implementations of Java allow you to choose between different garbage collectors using command line options.

Finally, it doesn't really matter how the GC is implemented in a Java or .net implementation provided that it can be made to work as required by the application. And for Java, the answer is that it can for most kinds of application. (The exceptions are typically systems/applications with hard real time requirements or very tight memory constraints.)

Stephen C
But for some background theory and basics: http://stackoverflow.com/questions/2910224/java-garbage-collection/2922042#2922042
Andreas_D
@Andreas_D - there are more detailed descriptions of the Java GC around than the one referenced. And both of the referenced pages are old. The Java GCs have definitely changed significantly since 1.4.1.
Stephen C
A: 

I found this link from my other question on SO that answers a little bit about the differences of garbage collection in Java and .NET/C#. For others who are looking for this kind of information, here it is-

In Java objects are created on the heap using the new keyword. Most classes in C# are created on the heap by using the new keyword. Also just as the JVM manages the destruction of objects so also does the CLR via a Mark and Compact garbage collection algorithm

NOTE: C# also supports stack-based classes, called value types, which are discussed further below.

CodeToGlory
http://www.brpreiss.com//books/opus5/html/page428.html has good info and Marc and compact algorithm.
CodeToGlory