4.Java Basics: Memory management mechanism for Java objects

Source: Internet
Author: User

1. Use new to create objects, allocate object space in heap memory, initialize;

2. Define a local variable in the method stack and eat a reference to the object in the heap memory;

3. The method executes the return, the stack memory is freed automatically, the local variable destroys;

4. If the heap in-memory object does not have a variable to reference it, becomes garbage, has garbage collector reclaimed, frees up the occupied heap memory

5.Java garbage collector

(1) The Java Runtime System has a garbage collection thread responsible for purging objects that are no longer used, commonly known as garbage collector;

(2) The garbage collector scans the memory periodically, marking the objects used, and clearing unmarked objects after the possible path scan ends

(3) The objects to be recycled are:

A. An object that is no longer referenced by any variable;

B. The reference variable is automatically discarded;

C. Artificially placing a reference variable as null

4.Java Basics: Memory management mechanism for Java objects

Related Article

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.