Java Memory Management

Source: Internet
Author: User

I. jvm Memory Structure

Program Counter Register, JVM Virtual Machine stack (JVM Stacks), Native Method Stacks, Heap, and Method Area)

(1) PCR
Follows the thread life cycle and records the number of. class bytecode lines currently executed for multi-thread operations.
(2) JVM Stacks
Stores data in method execution following the thread Lifecycle

(3) Native Method Stacks
Native method, such as hashCodes () in an object
(4) Heap
Stores all instance objects and array objects with built-in GC
(5) Method Area

Heap components, but does not force GC. The stored objects include the runtime constant pool, static variables, and class information loaded by JVM.


Ii. Garbage Collection
Garbage collection is required in the heap and method areas. The other three are created and destroyed along with the thread lifecycle.
Spam Determination Algorithm
(1) Reference calculator: Objects referenced in cycles cannot be recycled.

(2) root search: inefficient


Garbage removal Algorithm
(1) mark and clear Algorithms
Process: When the memory is insufficient, stop the program, traverse the GC Root, mark the reachable objects as surviving objects, and clear all unused objects.
Disadvantages: low efficiency; non-sequential idle memory
(2) replication algorithm
Process: the memory is divided into two parts: the active zone and the idle zone. The newly allocated active zone exists. When the memory is insufficient, GC is performed.
Surviving objects are placed in idle intervals in order.
Disadvantage: half of the memory is wasted; when the object survival rate is high, the replication operation is charged.
(3) tagging and sorting algorithms
Process: similar to (1) marking all surviving objects, re-moving objects in the memory order, and clearing the end memory
Disadvantage: Low Efficiency
(4) Generational search algorithms
Process: perform different collection algorithms for different objects.
Dead objects (local variables and temporary variables): replication algorithm (80% memory allocation objects + 10% active areas + 10% idle intervals)
Old and undead objects (Cache objects, database connection objects, and Singleton objects): tagging and sorting algorithms
Non-extinct object (String pool object, class information): Tag, Sorting Algorithm

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.