"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > The finalize() method

The finalize() method

Published on 2024-07-31
Browse:833

O método finalize( )

The finalize( ) method

  • The finalize() method can be defined to be called before an object is destroyed by the garbage collector.

  • finalize() ensures that an object is completely eliminated, like closing an open file.

  • To add a finalizer, define the finalize() method in the class.

  • The Java Runtime calls finalize() before recycling an object of the class.

  • General form of the method:
    protected void finalize( )
    {
    // part where the completion code goes
    }

  • The protected keyword limits access to finalize().

  • finalize() is called before garbage collection, not when an object goes out of scope.

  • It is not guaranteed when, or if, finalize() will be executed.

  • If the program terminates before garbage collection, finalize() will not be executed.

  • finalize() should be used as a fallback procedure for appropriate handling of special resources or applications.

  • finalize() is a specialized method and is rarely needed in most programs.

Release Statement This article is reproduced at: https://dev.to/devsjavagirls/o-metodo-finalize--3heh?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3