The garbage collection mechanism is a dynamic storage allocation solution. It automatically releases allocated memory blocks that are no longer needed by the program. The process of automatic memory recovery is called garbage collection. The garbage
from the root set to identify which objects are reachable,Which objects are not reachable and mark them in some way. For example, you can set one or more places for each reachable object. During scanning and identification, garbage collection based on tracing algorithms is also called marking and clearing.(Mark-and-sweep) ga
the concept of root set. The Garbage Collector Based on the tracing algorithm scans the root set to identify which objects are reachable and which objects are not reachable, and marks the reachable objects in some way, for example, you can set one or more places for each reachable object. In the scanning and identification process, the garbage
allocation and recovery. Java platform uses the Garbage Collector for automatic memory management. This greatly reduces the workload of developers.
I. Java garbage collection mechanism
The Java garbage collector is responsible for completing three tasks:
1. allocate memory
2. Ensure that the memory of the referenced
suitable for single processor machines. Of course, this collector can also be used on multiprocessor machines with small amounts of data (around 100M). You can use-XX:+USESERIALGC to open it.Parallel CollectorFigure 9 Parallel collector
Parallel garbage collection for young generations can reduce garbage collection t
counting. It uses the concept of root set. The Garbage Collector Based on the tracing algorithm scans the root set to identify which objects are reachable and which objects are not reachable, and marks the reachable objects in some way, for example, you can set one or more places for each reachable object. In the scanning and identification process, the garbage
collector).
Conclusion
The focus of this article is not to persuade you to use different programming languages or tools. Just want to bring the right understanding of the garbage collector. Garbage collection is a very challenging job, and many computer scientists have spent decades on it, so it is unlikely that a new GC algorithm will be available one night,
run2. Use System.GC () to request Java garbage collection regardless of which garbage collection algorithm the JVM is using. There is a parameter in the command line-VERBOSEGC can view the heap memory used by Java, which is in the following format:JAVA-VERBOSEGC ClassfileYou can look at an example:Class TESTGC{public
Serial collector for JAVA Garbage Collector and serial for garbage collection
1. Features
The Serial collector is the most basic and oldest collector in the Java Virtual Machine. It was the only choice for collecting new generations of Java virtual machines before JDK 1.3.1. The Serial collector is a single-threaded collector, but its "Single-threaded" doesn't ju
algorithmGarbage collector.Perspective Java Garbage Collection1. Command line parameter perspective garbage collector run2. Use System.GC () to request Java garbage collection regardless of which garbage collection algorithm the
characteristics of each block. Taking hot Spot virtual machine As an example, it divides the Java heap into Cenozoic and old generation, so that the most appropriate collection algorithm can be used according to the characteristics of each age.
Garbage collector classification
The hotspot virtual machine that is based on JDK 1.7 Update 14 contains all the
alternately. Each time, the garbage collection thread collects only a small area of memory space, and then switches to the application thread. Repeat until garbage collection is complete. In this way, due to the intermittent execution of the application code during the garbage
): Describes some useful but not necessary objects, When a memory overflow is about to occur, the JDK provides softreference to implement soft references, weak references (Weak Reference): Used to describe non-essential objects, weaker than soft references, objects associated with weak references can only survive until the next garbage collection occurs. Garbage
reference count of the object is set to 1. For example, create a new object a a=new a (), and then A is assigned to another variable B, that is, b=a; then the reference count of object A is +1. When any other variable is assigned to a reference to this object, the count is plus 1. When an object's reference exceeds its lifetime or is set to a new value, the object's reference count is reduced by 1, such as B=c, then A's reference count-1. Any object
additional space to store the reference count value. The biggest drawback of the reference count algorithm is that it cannot process circular references, as shown in:
Here, the blue objects are neither reachable nor recoverable, because each other references each other and their respective count values are not 0. This situation is powerless to reference the counting algorithm, other garbage collection
Java garbage collection mechanismWhen it comes to garbage collection (garbage collection,gc), many people naturally connect it to Java. In Java, programmers don't have to worry about memory dynamic allocations and
Java garbage collection mechanismWhen it comes to garbage collection (garbage collection,gc), many people naturally connect it to Java. In Java, programmers don't have to worry about memory dynamic allocations and
Java garbage collection mechanismWhen it comes to garbage collection (garbage collection,gc), many people naturally connect it to Java. In Java, programmers don't have to worry about memory dynamic allocations and
Source: HaiziWhen it comes to garbage collection (garbage collection,gc), many people naturally connect it to Java. In Java, programmers don't have to worry about memory dynamic allocations and garbage collection issues, all of wh
When it comes to garbage collection (garbage collection,gc), many people naturally connect it to Java. In Java, programmers don't have to worry about memory dynamic allocations and garbage collection issues, all of which are given
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.