Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JVM garbage collection algorithm

Tags:

jvm

I know there are different garbage collection algorithms. Those are Copy collection and Mark Compact collection, Incremental collection. I have a query now. Which algorithm is used in JVM? Why there are different algorithm available?

like image 537
user900721 Avatar asked May 01 '12 15:05

user900721


People also ask

What algorithm does Java use for garbage collection?

The Mark-Sweep algorithm is the most common garbage collection algorithm, which performs two operations. It first marks the objects to be garbage-collected in the memory space and then clears the marked objects up from the heap.

What is the algorithm of garbage collection?

Compacting garbage collectors typically use an algorithm like mark-sweep, but also re-arrange the objects to coalesce free-space to avoid fragmentation. This also often has the benefit of keeping the objects in memory ordered by their allocation time, which typically improves the locality of reference.

How does JVM garbage collection work?

As long as an object is being referenced, the JVM considers it alive. Once an object is no longer referenced and therefore is not reachable by the application code, the garbage collector removes it and reclaims the unused memory.

Does the JVM do garbage collection?

Java garbage collection is an automatic process. The programmer does not need to explicitly mark objects to be deleted. The garbage collection implementation lives in the JVM. Each JVM can implement garbage collection however it pleases; the only requirement is that it meets the JVM specification.


1 Answers

First off, there is more than one version of the JVM.

I believe most major JVM's are using a generational garbage collection by default. They may also use a hybrid strategy however.

Here are some links on major JVM's using generational garbage collection:

  • OJVM Generational collection
  • Hotspot JVM

Here is a great article I found that indicates Jrockit uses a marking strategy: Comparison of three Major JVM's

like image 105
stevebot Avatar answered Dec 12 '22 15:12

stevebot