Memory Analytics Experience Posts

Source: Internet
Author: User

Take a few posts with you to learn about the methods of memory analysis. Let's talk about it this time. Memory leaks: We know that the JVM performs GC according to Generation (generation), which is divided into young generation (younger generation), tenured generation (old age), Permanent Generation (permanent, Perm Gen), Perm Gen (or non-heap non-heap) is a heterogeneous one, which will be explained later. Note that the heap space does not include Perm Gen. The vast majority of the objects are assigned in young generation, and also in young generation, when young generation's space is filled, the GC will minor collection (secondary recovery), This recovery does not involve other Generation,minor in the heap collection according to weak generational hypothesis (weak-age hypothesis) to assume that a large number of objects in young generation are garbage collection. The process of minor collection will be very fast. The objects that were not reclaimed in young generation are transferred to the tenured generation, but tenured generation is also filled, eventually triggering major collection (Master Recycle), which is for the entire heap, Because of the large number of objects involved, so much slower than minor collection. The JVM has three kinds of garbage collector, which is throughput collector, which is used for parallel young generation recovery, which is initiated by the parameter-XX:+USEPARALLELGC; concurrent low pause collector, Used to do tenured generation concurrent collection, initiated by the parameter-XX:+USECONCMARKSWEEPGC, incremental low pause collector, can be considered as the default garbage collector. It is not recommended to use a garbage collector directly, it is best to let the JVM decide for itself, unless you are confident enough. How are the generation spaces in the heap divided? The-xmx=n parameter of the JVM allows you to specify the maximum heap space, while-xms=n specifies the minimum heap space. In the case of JVM initialization, if the minimum heap space is less than the maximum heap space, the JVM shown will mark unused space as virtual. Besides these two parameters, there's-XX:MINHEAPFR.Eeratio=n and-xx:maxheapfreeratio=n, respectively, control the maximum and minimum ratio of the remaining space to the active object. Back to the question "Why is memory overflow?" ”。 To answer this question and to elicit another topic, what kind of object GC will be recycled? Of course, the GC finds that the object is reclaimed by any reference chain (reference chain) that cannot access an object. The noun GC Roots is the starting point for the analysis of the process, such as the JVM itself ensuring the accessibility of the object (then the JVM is GC Roots), so the GC Roots is how to keep the object reachable in memory and, once unreachable, is recycled. Typically GC roots is an object on the call stack (the calling stack) on the current thread (for example, method parameters and local variables), or either the thread itself or the System class loader (the ClassLoader) The class that is loaded and the active object that native code (local code) retains. So GC roots is a powerful tool for analyzing why objects still exist in memory. If you know what kind of object GC will be recycled, then learn what the object references contain.  From the strongest to the weakest, different reference (reachable) levels reflect the life cycle of the object.  Strong ref (strong quote): Usually we write code that is strong Ref, which corresponds to strong accessibility, and the object is recycled only if you remove the strong. Soft Ref (Soft Reference): corresponds to soft accessibility, so long as there is enough memory, the object is persisted until the memory is found to be tight and no strong Ref is collected.  Generally available for caching, implemented through the Java.lang.ref.SoftReference class. Weak ref (weak reference): is weaker than soft ref, and when no strong ref is found, the object is reclaimed immediately without waiting for the memory to be tight.  Implemented through the Java.lang.ref.WeakReference and Java.util.WeakHashMap classes. Phantom ref (Virtual Reference): No object is persisted in memory, you can only use Phantom ref itself. Typically used to perform a special cleanup process after entering the Finalize () method, implemented through Java.lang.ref.PhantomReference. With all the above I believe it's easy to get the heap and Perm Gen to burst, yes. Use strong Ref to store large amounts of data until the heap burst; use interned strings (or class loader to load a large number of classes) to burst Perm Gen. 

Memory Analytics experience post

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.