Object finalize processing method, objectfinalize

Source: Internet
Author: User

Object finalize processing method, objectfinalize

We know that everything in java is an object. If you create a class, you can override the finalize method in the parent class. When will this method be called?
When the VM's garbage collector detects that this object is not reachable, that is to say, when this object can be recycled as garbage, the finalize () method of this object will be executed, by default, it is not processed. We can rewrite this method to release resources. This is generally not recommended because it costs a lot.

`    @Override    protected void finalize() throws Throwable {        super.finalize();    }

This method also has a note, which can be determined to be called, but we can call it.

Runtime.getRuntime().runFinalization()

Gc is recommended to call this method, but it cannot be guaranteed to be called.
In fact, the finalize method does not have any logic in the object class and is only useful for rewriting. If you must use this method, you can explicitly specify the call.

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.