Proficient in the life cycle of Hibernate--java objects in the JVM

Source: Internet
Author: User

When an application creates an object from a new statement, the JVM allocates a piece of memory space for the object, which is always in memory as long as the object is referenced by a reference variable. When the object is not referenced by any object, his life cycle means the end, and the JVM reclaims the object at the appropriate time. The following life cycle is demonstrated by code:

Customer C= NewCustomer ("Tom",NewHashSet ());OrderO1= New Order("tom_order001",NULL);OrderO2= New Order("tom_order002",NULL); O1.Setcustomer (c); c.GetOrders ().Add (O1); O1= NULL;//Line sixthO2= NULL;//Line SeventhC= NULL;//Line eighth

For O2, at the end of the seventh line life cycle, for O1 at the end of the eighth line life cycle.
When executing:

=new Customer("Tom",new HashSet());Order=newOrder("Tom_order001",null);Order=newOrder("Tom_order002",null);


When executing:

o1.setCustomer(c);c.getOrders().add(o1);


When O1 is set to NULL, the life cycle of the Order1 object does not end, although O1 no longer references the Order1 object because the Orders collection of the customer object also holds a reference to the Order1 object.
When O2 is set to NULL, the Order2 object is no longer referenced by any reference variable, so the life cycle ends.

Proficient in the life cycle of Hibernate--java objects in the JVM

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.