Fourth chapter initialization and cleanup

Source: Internet
Author: User

First, the construction method

1. Default Construction method

Second, method overloading (the way)

1, the use of the Order of parameters

2. Data types Using Parameters

3, the use of the number of parameters

4. Use different return types (method type)

Third, the keyword this

1. Call the constructor method in the constructor method

    • The call action of the constructor must be placed at the very beginning Constructor the must is the first statement in a Constructor
    • So only one other constructor can be called inside each constructor

Iv. cleanup: End and garbage collection

V. Member initialization

Vi. Summary

This chapter is mainly about initialization and garbage cleanup, this book is the description of the initialization is a relatively basic knowledge, relatively familiar with, and garbage cleanup is automatically executed by the "garbage collector", relatively unfamiliar.

The "garbage collector" does bring great convenience to the programmers, and the functionality is quite powerful. It operates in a variety of ways, such as: reference counting (reference counting, a simple, slow GC technique; counting, which is the number of times the object is referenced, and the memory it consumes when the counter is 0 o'clock). However, in order to speed up, its true principle is based on "live on stack (stack) or static storage (static storage space)" On the reference and tracked to the object, is still the object, not found the object will naturally become garbage, this way, The JVM uses a "self-reflection (adaptive)" garbage collection mechanism. As for how to deal with surviving objects, there are "copy collectors", "Mark and Sweep", "stop-and-copy" and so on. Different JDK versions will have different garbage collection mechanisms, but this book is written for Java 2, now Java 8 may have a faster, better, more secure "garbage collector" (in the future to continue to study), but in any case, the "garbage collector" still has a plain understanding.

Even though the "garbage collector is powerful", there are drawbacks. The "garbage collector" only knows to release the memory that is allocated through new, so it does not know how to release the "Special Memory" that your object occupies (objects are allocated some storage space in ways other than "object Generation"), and you need to use the Finalize () function, which allows you to " The garbage collection moment "performs some important (your own) cleanup actions. However, the Finalize function (and perhaps some other related functions) is used in detail and when it is used, I have not actually manipulated it.

In short, there is a very vague understanding of the "garbage collector". Have the opportunity to continue to study further in the future.

Fourth chapter initialization and cleanup

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.