Describe the GC mechanism of the JVM, commonly used JVM tuning methods, how to generate oom, how to deal with oom problems?

Source: Internet
Author: User
Tags data structures
GC mechanism: Allocating an object using the new keyword; when releasing an object, the program cannot access the object again, as long as it is assigned NULL to all references to the object, and we call the object "unreachable." The GC is responsible for reclaiming the memory space of all "unreachable" objects.
JVM Tuning Method:
1. The most basic advice is to release the references to unwanted objects as soon as possible.
Most programmers use temporary variables when they leave the reference variable behind the active field (scope). Automatically set to null. When we use this method, we must pay special attention to some complex object graphs, such as arrays, queues, trees, graphs and so on, which are more complex to be related to each other. GC recycling is generally less efficient for such objects. If the program allows, assign the unused reference object to NULL as soon as possible. This can speed up the work of GC.
2. Use the Finalize function as little as possible. A finalize function is the opportunity that Java provides to programmers to release objects or resources. However, it increases the amount of GC effort and therefore minimizes the use of finalize methods to reclaim resources.
3. If you need to use a picture that you use frequently, you can use soft to apply the type. As much as possible, it can save pictures in memory for program invocation without causing outofmemory.
4. Note the collection data types, including arrays, trees, graphs, lists, and other data structures, these data structures for GC, recovery more complex. In addition, note some global variables, as well as some static variables. These variables tend to cause suspension objects (dangling reference), causing memory waste.
5. When the program has a certain waiting time, the programmer can manually execute System.GC () to notify the GC to run, but the Java language specification does not guarantee that the GC will execute. Using an incremental GC can shorten the pause time for Java programs.



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.