The life cycle of a Java object

Source: Internet
Author: User

Original address: http://leihuang.net/2014/11/13/Object-Lifecycle/


What is an object
    • Objects are collections of data and behavior
    • An object is an instance of a class
    • Object has state and behavior
Creating objects

Creating objects with the New keyword is one of the most common methods in Java.

Object life cycle
    1. Created
    2. In use
    3. Invisible
    4. Unreachable
    5. Collected
    6. Finalized
    7. De-allocated

Such as

Created

The following is the some actions performed when a object is created,new memory was allocated for an object.

Once The object has been created, assuming that it's assigned to some variable and then it directly moves to the on use s Tate.

In use

Objects that is held by at least one strong reference is considered to being "in use".

Invisible

An object was in the ' Invisible ' state when there was no longer any strong references that was accessible to the program, E Ven though there might still be references.

Unreachable

An object enters a "unreachable" state when the no more strong references to it exist. When an object was unreachable then it was a state for collection.

It is the important to note, just any strong reference would hold an object in memory. These must be references this chain from a garbage collection root.

Garbage collection roots is a special class of variable that includes,temporary variables on the stack

Collected

An object was in the ' collected ' state when the garbage collector have recognized an object as unreachable and readies it fo R final processing as a precursor to de-allocation. If the object has a Finalize method, then it's marked for finalization.

Finalized

An object was in the "finalized" state if it was still unreachable after it's Finalize method, if any, have been run. A finalized object is awaiting de-allocation. If you is considering using a finalizer to ensure that important resources is freed in a timely manner, you might want t O reconsider. To lengthening object lifetimes, finalize methods can increase object size.

De-allocated

The de-allocated state was the final step in garbage collection. If an object was still unreachable after all the above work has been done and then this is the state for de-allocation.

2014-11-13 17:53:46

Brave,happy,thanksgiving!


Life cycle of 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.