dz̸PHP5ÖÐÀ¬»ø»ØÊÕËã·¨(Garbage Collection)µÄÑÝ»¯(2)
PHP5.2ÖеÄÀ¬»ø»ØÊÕËã·¨¡ª¡ªReference Counting
PHP5.2ÖÐʹÓõÄÄÚ´æ»ØÊÕËã·¨ÊÇ´óÃû¶¦¶¦µÄReference Counting£¬ Õâ¸öËã·¨ÖÐÎÄ·Òë½Ð×ö¡°ÒýÓüÆÊý¡±£¬Æä˼Ïë·Ç³£Ö±¹ÛºÍ¼ò½à£ºÎªÃ¿¸öÄÚ´æ¶ÔÏó·ÖÅäÒ»¸ö¼ÆÊýÆ÷£¬µ±Ò»¸öÄÚ´æ¶ÔÏó½¨Á¢Ê±¼ÆÊýÆ÷³õʼ»¯Îª1£¨Òò´Ë´Ëʱ×ÜÊÇÓÐÒ»¸ö±ä Á¿ÒýÓô˶ÔÏ󣩣¬ÒÔºóÿÓÐÒ»¸öбäÁ¿ÒýÓôËÄÚ´æ¶ÔÏó£¬Ôò¼ÆÊýÆ÷¼Ó1£¬¶øÿµ±¼õÉÙÒ»¸öÒýÓôËÄÚ´æ¶ÔÏóµÄ±äÁ¿Ôò¼ÆÊýÆ÷¼õ1£¬µ±À¬»ø»ØÊÕ»úÖÆÔË×÷µÄʱºò£¬½«ËùÓÐ ¼ÆÊýÆ÷Ϊ0µÄÄÚ´æ¶ÔÏóÏú»Ù²¢»ØÊÕÆäÕ¼ÓõÄÄÚ´æ¡£¶øPHPÖÐÄÚ´æ¶ÔÏó¾ÍÊÇzval£¬¶ø¼ÆÊýÆ÷¾ÍÊÇrefcount__gc¡£
ÀýÈçÏÂÃæÒ»¶ÎPHP´úÂëÑÝʾÁËPHP5.2¼ÆÊýÆ÷µÄ¹¤×÷ÔÀí£¨¼ÆÊýÆ÷ֵͨ¹ýxdebugµÃµ½£©£º
<?php $val1 = 100; //zval(val1).refcount_gc = 1; $val2 = $val1; //zval(val1).refcount_gc = 2,zval(val2).refcount_gc = 2(ÒòΪÊÇWrite on copy£¬µ±Ç°val2Óëval1¹²Í¬ÒýÓÃÒ»¸özval) $val2 = 200; //zval(val1).refcount_gc = 1,zval(val2).refcount_gc = 1(´Ë´¦val2н¨ÁËÒ»¸özval) unset($val1); //zval(val1).refcount_gc = 0($val1ÒýÓõÄzvalÔÙÒ²²»¿ÉÓ㬻ᱻGC»ØÊÕ) ?>Reference Counting¼òµ¥Ö±¹Û£¬ÊµÏÖ·½±ã£¬µ«È´´æÔÚÒ»¸öÖÂÃüµÄȱÏÝ£¬¾ÍÊÇÈÝÒ×Ôì³ÉÄÚ´æй¶¡£ºÜ¶àÅóÓÑ¿ÉÄÜÒѾÒâʶµ½ÁË£¬Èç¹û´æÔÚÑ»·ÒýÓã¬ÄÇôReference Counting¾Í¿ÉÄܵ¼ÖÂÄÚ´æй¶¡£ÀýÈçÏÂÃæµÄ´úÂ룺
<?php $a = array(); $a[] = & $a; unset($a); ?>
Õâ¶Î´úÂëÊ×ÏȽ¨Á¢ÁËÊý×éa£¬È»ºóÈÃaµÄµÚÒ»¸öÔªËØ°´ÒýÓÃÖ¸Ïòa£¬ÕâʱaµÄzvalµÄrefcount¾Í±äΪ2£¬È»ºóÎÒÃÇÏú»Ù±äÁ¿a£¬´Ëʱa×î³õÖ¸ÏòµÄzvalµÄrefcountΪ1£¬µ«ÊÇÎÒÃÇÔÙҲûÓа취¶ÔÆä½øÐвÙ×÷£¬ÒòΪÆäÐγÉÁËÒ»¸öÑ»·×ÔÒýÓã¬ÈçÏÂͼËùʾ£º
ÆäÖлÒÉ«²¿·Ö±íʾÒѾ²»¸´´æÔÚ¡£ÓÉÓÚa֮ǰָÏòµÄzvalµÄrefcountΪ1£¨±»ÆäHashTableµÄµÚÒ»¸öÔªËØÒýÓã©£¬Õâ¸özval¾Í²»»á±»GCÏú»Ù£¬Õⲿ·ÖÄÚ´æ¾Íй¶ÁË¡£
ÕâÀïÌرðÒªÖ¸³öµÄÊÇ£¬PHPÊÇͨ¹ý·ûºÅ±í£¨Symbol Table£©´æ´¢±äÁ¿·ûºÅµÄ£¬È«¾ÖÓÐÒ»¸ö·ûºÅ±í£¬¶øÿ¸ö¸´ÔÓÀàÐÍÈçÊý×é»ò¶ÔÏóÓÐ×Ô¼ºµÄ·ûºÅ±í£¬Òò´ËÉÏÃæ´úÂëÖУ¬aºÍa[0]ÊÇÁ½¸ö·ûºÅ£¬µ«ÊÇa´¢´æÔÚÈ«¾Ö ·ûºÅ±íÖУ¬¶øa[0]´¢´æÔÚÊý×é±¾ÉíµÄ·ûºÅ±íÖУ¬ÇÒÕâÀïaºÍa[0]ÒýÓÃͬһ¸özval£¨µ±È»·ûºÅaºóÀ´±»Ïú»ÙÁË£©¡£Ï£Íû¶ÁÕßÅóÓÑ×¢Òâ·ÖÇå·ûºÅ £¨Symbol£©µÄzvalµÄ¹Øϵ¡£
ÔÚPHPÖ»ÓÃÓÚ×ö¶¯Ì¬Ò³Ãæ½Å±¾Ê±£¬ÕâÖÖй¶ҲÐí²»ÊǺÜÒª½ô£¬ÒòΪ¶¯Ì¬Ò³Ãæ½Å±¾µÄÉúÃüÖÜÆں̣ܶ¬PHP»á±£Ö¤µ±½Å±¾Ö´ÐÐÍê±Ïºó£¬ÊÍ·ÅÆäËùÓÐ×ÊÔ´¡£µ«ÊÇ PHP·¢Õ¹µ½Ä¿Ç°ÒѾ²»½ö½öÓÃ×÷¶¯Ì¬Ò³Ãæ½Å±¾Õâô¼òµ¥£¬Èç¹û½«PHPÓÃÔÚÉúÃüÖÜÆڽϳ¤µÄ³¡¾°ÖУ¬ÀýÈç×Ô¶¯»¯²âÊԽű¾»òdeamon½ø³Ì£¬ÄÇô¾¹ý¶à´ÎÑ»· ºó»ýÀÛÏÂÀ´µÄÄÚ´æй¶¿ÉÄܾͻáºÜÑÏÖØ¡£Õâ²¢²»ÊÇÎÒÔÚËÊÈËÌýÎÅ£¬ÎÒÔø¾ÊµÏ°¹ýµÄÒ»¸ö¹«Ë¾¾Íͨ¹ýPHPдµÄdeamon½ø³ÌÀ´ÓëÊý¾Ý´æ´¢·þÎñÆ÷½»»¥¡£
ÓÉÓÚReference CountingµÄÕâ¸öȱÏÝ£¬PHP5.3¸Ä½øÁËÀ¬»ø»ØÊÕËã·¨¡£
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ