JAVA: Purging and recycling of objects

Source: Internet
Author: User

The elimination of objects, that is, garbage collection.

There are two methods related to purging objects:Finalize () and GC ().

(1), this finalize () method is a method of the object class, and any class inherits this method from object.

Note the Finalize () method is called before the object is disposed of as garbage from memory, rather than before the object becomes garbage. But this garbage collector's enablement is not controlled by the programmer, and will not be aroused when the garbage is generated, even if the program terminates, it does not start the opportunity.

As a result, Java provides a System.GC () method to force the garbage collector to recycle, that is, make a call to finalize () to clean up the garbage.

Here's an example:

Tcabinetcard Cabinetcard=t.gettcabinetcardservice (). Get (Strs[1].tostring ()); if (Null==cabinetcard) {Session.write ("Card Error");} else if (Cabinetcard.getcardtype (). Equals ("0")) {Session.write (jsonmapper.tojsonstring (Cabinetcard));} else if (Cabinetcard.getcardtype (). Equals ("2")) {//tcabinetcard cabinetcard = new Cabinetcard; System.GC (); Cabinetcard.setcardtype ("2");//re-assign list List=t.gettcabinetcardservice (). Findlist (Cabinetcard); Session.write (jsonmapper.tojsonstring (list));} else if (Cabinetcard.getcardtype () Equals ("1")) {session.write ("Super User");}

Do not use the new object

The third judgment is judged by the type in the object, which takes the property of the entire object, and reclaims the current object for assignment.


Details to start 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0058.gif "alt=" J_0058.gif "/>650" this.width=650; " Src= "Http://img.baidu.com/hi/jx2/j_0058.gif" style= "White-space:normal; alt=" J_0058.gif "/>650) this.width=650 , "src=" Http://img.baidu.com/hi/jx2/j_0058.gif "style=" White-space:normal; alt= "J_0058.gif"/>

JAVA: Purging and recycling of objects

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.