ÓÐʱµ±³·ÏûÒ»¸ö¶ÔÏóʱ£¬ÐèÒªÍê³ÉһЩ²Ù×÷¡£ÀýÈ磬Èç¹ûÒ»¸ö¶ÔÏóÕýÔÚ´¦ÀíµÄÊÇ·ÇJava ×ÊÔ´£¬ÈçÎļþ¾ä±ú»òwindow ×Ö·û×ÖÌ壬ÕâʱÄãҪȷÈÏÔÚÒ»¸ö¶ÔÏó±»³·ÏûÒÔÇ°Òª±£Ö¤ÕâЩ×ÊÔ´±»ÊÍ·Å¡£Îª´¦ÀíÕâÑùµÄ×´¿ö£¬Java ÌṩÁ˱»³ÆΪÊÕ⣨finalization £©µÄ»úÖÆ¡£Ê¹ÓøûúÖÆÄã¿ÉÒÔ¶¨ÒåһЩÌØÊâµÄ²Ù×÷£¬ÕâЩ²Ù×÷ÔÚÒ»¸ö¶ÔÏó½«Òª±»À¬»ø»ØÊÕ³ÌÐòÊÍ·ÅʱִÐС£
Òª¸øÒ»¸öÀàÔö¼ÓÊÕ⣨finalizer £©£¬ÄãÖ»Òª¶¨Òåfinalize ( ) ·½·¨¼´¿É¡£Java »ØÊÕ¸ÃÀàµÄÒ»¸ö¶ÔÏóʱ£¬¾Í»áµ÷ÓÃÕâ¸ö·½·¨¡£ÔÚfinalize ( )·½·¨ÖУ¬ÄãÒªÖ¸¶¨ÔÚÒ»¸ö¶ÔÏó±»³·ÏûÇ°±ØÐëÖ´ÐеIJÙ×÷¡£À¬»ø»ØÊÕÖÜÆÚÐÔµØÔËÐУ¬¼ì²é¶ÔÏó²»ÔÙ±»ÔËÐÐ״̬ÒýÓûò¼ä½ÓµØͨ¹ýÆäËû¶ÔÏóÒýÓ᣾ÍÔÚ¶ÔÏó±»ÊÍ·Å֮ǰ£¬Java ÔËÐÐϵͳµ÷ÓøöÔÏóµÄfinalize( ) ·½·¨¡£
finalize()·½·¨µÄͨÓøñʽÈçÏ£º
protected void finalize( )
{
// finalization code here
}
ÆäÖУ¬¹Ø¼ü×ÖprotectedÊÇ·ÀÖ¹ÔÚ¸ÃÀàÖ®ÍⶨÒåµÄ´úÂë·ÃÎÊfinalize()±êʶ·û¡£¸Ã±êʶ·ûºÍÆäËû±êʶ·û½«ÔÚµÚ7ÕÂÖнâÊÍ¡£
Àí½âfinalize( ) ÕýºÃÔÚÀ¬»ø»ØÊÕÒÔÇ°±»µ÷Ó÷dz£ÖØÒª¡£ÀýÈçµ±Ò»¸ö¶ÔÏ󳬳öÁËËüµÄ×÷ÓÃÓòʱ£¬finalize( ) ²¢²»±»µ÷Óá£ÕâÒâζ×ÅÄã²»¿ÉÄÜÖªµÀºÎʱ----ÉõÖÁÊÇ·ñ----finalize( ) ±»µ÷Óá£Òò´Ë£¬ÄãµÄ³ÌÐòÓ¦¸ÃÌṩÆäËûµÄ·½·¨À´ÊÍ·ÅÓɶÔÏóʹÓõÄϵͳ×ÊÔ´£¬¶ø²»ÄÜÒÀ¿¿finalize( ) À´Íê³É³ÌÐòµÄÕý³£²Ù×÷¡£
×¢Ò⣺Èç¹ûÄãÊìϤC++£¬ÄÇÄãÖªµÀC++ÔÊÐíÄãΪһ¸öÀඨÒåÒ»¸ö³·Ïûº¯Êý£¨destructor £©£¬ËüÔÚ¶ÔÏóÕýºÃ³ö×÷ÓÃÓò֮ǰ±»µ÷Óá£Java²»Ö§³ÖÕâ¸öÏë·¨Ò²²»Ìṩ³·Ïûº¯Êý¡£finalize() ·½·¨Ö»ºÍ³·Ïûº¯ÊýµÄ¹¦Äܽӽü¡£µ±Äã¶ÔJava Óзḻ¾Ñéʱ£¬Ä㽫¿´µ½ÒòΪJavaʹÓÃÀ¬»ø»ØÊÕ×Óϵͳ£¬¼¸ºõûÓбØҪʹÓó·Ïûº¯Êý¡£