Comparison of garbage collection mechanisms in Java and. Net

Source: Internet
Author: User

Same point:

Have adopted the mechanism of generational.

Both support concurrent GC.

Have not adopted the reference counting method, but have adopted the tracking technology.

. NET, you can pass the code GC. Collect () enforces that the CLR is garbage collected (because garbage collection is asynchronous, the CLR has a dedicated thread responsible for garbage collection, so Even if you call Gc.collect, you do not call Finalize in real time, so to ensure that the destructor is actually called, you can use the statement gc.waitforpendingfinalizers () to ensure that the destructor is really running, refer to http://cnn237111.blog.51cto.com/2359144/1343004 )

garbage collection can also be enforced through System.GC () in Java. (In fact, it is only recommended that the JVM perform garbage collection, and the JVM does not necessarily do the recycling immediately.) )

Different points:

The CLR reserves a large space, called the large Object Heap (LOH), to be placed here when there are large objects (more than 85000 bytes) that need to be allocated space.

The difference between this place and the generational mechanism is that this place is recycled only when the full GC is in place, and the area is not compressed.


In Java, you can configure parameters so that large objects (greater than the set threshold) go directly to the old age (avoid doing a lot of copying on younger generations).

The memory that is reclaimed by the JVM is returned to the operating system only under certain conditions. (see:http://stackoverflow.com/questions/366658/java-6-excessive-memory-usage#367933)

. NET the recovered memory is returned directly to the operating system.


The JVM's garbage collection mechanism provides a number of configurable parameters.

The CLR's garbage collection mechanism is almost nothing to configure (the only configuration seems to be workstation mode (Workstation) and server mode (server)).


Both support concurrent GC. Java is a CMS collector that supports concurrent GC in the old age.

. NET concurrent GC is only available on the 2nd generation and only in workstation mode.


Java is divided into the young generation, the old age, the permanent generation.

. NET Sub-No. 0 generation, 1th generation, 2nd generation.


. NET used in the way of marking, compression.

Java is not limited to an algorithm because of its many collectors.


Young generation

Old age

Way

Serial collector

Replication Algorithms


Single thread, Stop the world

serialold Collector


Marker Grooming algorithm

Single thread, Stop the world

Parnew Collector

Replication Algorithms

Marker Grooming algorithm

Multithreading, Stop the World

Parallel Scavenge collector

copy algorithm                

Multithreading, Stop the World

CMS collector


Mark Clear

Single Thread

G1 Collector

Copy

Tag Grooming



Several articles on Java garbage collection

Http://www.cnblogs.com/shudonghe/p/3457990.html

http://blog.csdn.net/zhangerqing/article/details/8214365

. NET Garbage collection articles

https://msdn.microsoft.com/zh-cn/library/ee787088 (v=vs.110). aspx

Http://www.mincoder.com/article/4284.shtml

Comparison of garbage collection mechanisms in Java and. Net

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.