ʹÓÃunset()Ïú»Ù±äÁ¿²¢ÊÍ·ÅÄÚ´æ
תÔØ×Ô£ºhttp://www.okajax.com/a/201106/php_unset.html
PHPµÄunset()º¯ÊýÓÃÀ´Çå³ý¡¢Ïú»Ù±äÁ¿£¬²»ÓõıäÁ¿£¬ÎÒÃÇ¿ÉÒÔÓÃunset()½«ËüÏú»Ù¡£µ«ÊÇijЩʱºò£¬ÓÃunset()È´ÎÞ·¨´ïµ½Ïú»Ù±äÁ¿Õ¼ÓõÄÄڴ棡ÎÒÃÇÏÈ¿´Ò»¸öÀý×Ó
<?php $s=str_repeat('1',255); //²úÉúÓÉ255¸ö1×é³ÉµÄ×Ö·û´® $m=memory_get_usage(); //»ñÈ¡µ±Ç°Õ¼ÓÃÄÚ´æ unset($s); $mm=memory_get_usage(); //unset()ºóÔٲ鿴µ±Ç°Õ¼ÓÃÄÚ´æ echo $m-$mm; ?>×îºóÊä³öunset()֮ǰռÓÃÄÚ´æ¼õÈ¥unset()Ö®ºóÕ¼ÓÃÄڴ棬Èç¹ûÊÇÕýÊý£¬ÄÇô˵Ã÷unset($s)ÒѾ½«$s´ÓÄÚ´æÖÐÏú»Ù(»òÕß Ëµ£¬unset()Ö®ºóÄÚ´æÕ¼ÓüõÉÙÁË)£¬¿ÉÊÇÎÒÔÚPHP5ºÍwindowsƽ̨Ï£¬µÃµ½µÄ½á¹ûÊÇ£º-48¡£ÕâÊÇ·ñ¿ÉÒÔ˵Ã÷£¬unset($s)²¢Ã»ÓÐÆð µ½Ïú»Ù±äÁ¿$sËùÕ¼ÓÃÄÚ´æµÄ×÷ÓÃÄØ£¿ÎÒÃÇÔÙ×÷ÏÂÃæµÄÀý×Ó£º
<?php $s=str_repeat('1',256); //²úÉúÓÉ256¸ö1×é³ÉµÄ×Ö·û´® $m=memory_get_usage(); //»ñÈ¡µ±Ç°Õ¼ÓÃÄÚ´æ unset($s); $mm=memory_get_usage(); //unset()ºóÔٲ鿴µ±Ç°Õ¼ÓÃÄÚ´æ echo $m-$mm; ?>
Õâ¸öÀý×Ó£¬ºÍÉÏÃæµÄÀý×Ó¼¸ºõÏàͬ£¬Î¨Ò»µÄ²»Í¬ÊÇ£¬$sÓÉ256¸ö1×é³É£¬¼´±ÈµÚÒ»¸öÀý×Ó¶àÁËÒ»¸ö1£¬µÃµ½½á¹ûÊÇ£º224¡£ÕâÊÇ·ñ¿ÉÒÔ˵Ã÷£¬unset($s)ÒѾ½«$sËùÕ¼ÓõÄÄÚ´æÏú»ÙÁË£¿
ͨ¹ýÉÏÃæÁ½¸öÀý×Ó£¬ÎÒÃÇ¿ÉÒԵóöÒÔϽáÂÛ£º½áÂÛÒ»¡¢unset()º¯ÊýÖ»ÄÜÔÚ±äÁ¿ÖµÕ¼ÓÃÄÚ´æ¿Õ¼ä³¬¹ý256×Ö½Úʱ²Å»áÊÍ·ÅÄÚ´æ¿Õ¼ä¡£
ÄÇôÊDz»ÊÇÖ»Òª±äÁ¿Öµ³¬¹ý256£¬Ê¹ÓÃunset¾Í¿ÉÒÔÊÍ·ÅÄÚ´æ¿Õ¼äÄØ£¿ÎÒÃÇÔÙͨ¹ýÒ»¸öÀý×ÓÀ´²âÊÔһϣº
<?php $s=str_repeat('1',256); //ÕâºÍµÚ¶þ¸öÀý×ÓÍêÈ«Ïàͬ $p=&$s; $m=memory_get_usage(); unset($s); //Ïú»Ù$s $mm=memory_get_usage(); echo $p.'<br />'; echo $m-$mm; ?>Ë¢ÐÂÒ³Ã棬ÎÒÃÇ¿´µ½µÚÒ»ÐÐÓÐ256¸ö1£¬µÚ¶þÐÐÊÇ-48£¬°´Àí˵ÎÒÃÇÒѾÏú»ÙÁË$s£¬¶ø$pÖ»ÊÇÒýÓÃ$sµÄ±äÁ¿£¬Ó¦¸ÃÊÇûÓÐÄÚÈÝÁË£¬ÁíÍ⣬unset($s)ºóÄÚ´æÕ¼ÓÃÈ´±Èunset()Ç°Ôö¼ÓÁË£¡ÏÖÔÚÎÒÃÇÔÙ×öÒÔϵÄÀý×Ó£º
<?php $s=str_repeat('1',256); //ÕâºÍµÚ¶þ¸öÀý×ÓÍêÈ«Ïàͬ $p=&$s; $m=memory_get_usage(); $s=null; //ÉèÖÃ$sΪnull $mm=memory_get_usage(); echo $p.'<br />'; echo $m-$mm; ?>ÏÖÔÚË¢ÐÂÒ³Ã棬ÎÒÃÇ¿´µ½£¬Êä³ö$pÒѾÊÇûÓÐÄÚÈÝÁË£¬unset()Ç°ºóÄÚ´æÕ¼ÓÃÁ¿Ö®²îÊÇ224£¬¼´ÒѾÇå³ýÁ˱äÁ¿Õ¼ÓõÄÄÚ´æ¡£±¾ÀýÖеÄ$s=nullÒ²¿ÉÒÔ»»³Éunset()£¬ÈçÏ£º
<?php $s=str_repeat('1',256); //ÕâºÍµÚ¶þ¸öÀý×ÓÍêÈ«Ïàͬ $p=&$s; $m=memory_get_usage(); unset($s); //Ïú»Ù$s unset($p); $mm=memory_get_usage(); echo $p.'<br />'; echo $m-$mm; ?>
ÎÒÃǽ«$sºÍ$p¶¼Ê¹ÓÃunset()Ïú»Ù£¬ÕâʱÔÙ¿´ÄÚ´æÕ¼ÓÃÁ¿Ö®²îÒ²ÊÇ224£¬ËµÃ÷ÕâÑùÒ²¿ÉÒÔÊÍ·ÅÄÚ´æ¡£ÄÇô£¬ÎÒÃÇ¿ÉÒԵõ½ÁíÍâÒ»Ìõ½áÂÛ£º½áÂÛ¶þ¡¢Ö»Óе±Ö¸Ïò¸Ã±äÁ¿µÄËùÓбäÁ¿£¨ÈçÒýÓñäÁ¿£©¶¼±»Ïú»Ùºó£¬²Å»áÊÍ·ÅÄÚ´æ¡£
ÏàО¹ý±¾ÎĵÄÀý×Ӻ󣬴ó¼ÒÓ¦¸Ã¶Ôunset()ÓÐËùÁ˽âÁË£¬×îÆðÂ룬±¾ÈËÓÃunset()Ò²ÊÇΪÁËÔÚ±äÁ¿²»Æð×÷ÓÃʱ£¬ÊÍ·ÅÄÚ´æ¡£
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿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¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ