javascript ÄÚ´æ»ØÊÕ»úÖÆÀí½â
javascriptÓïÑÔÊÇÒ»ÃÅÓÅÐãµÄ½Å±¾ÓïÑÔ.ÆäÖаüº¬½Å±¾ÓïÑÔµÄÁé»îÐÔÍ⻹ӵÓÐÐí¶à¸ß¼¶ÓïÑÔµÄÌØÐÔ.ÀýÈç³äÐí¹¹½¨ºÍʵÀý»¯Ò»¸ö¶ÔÏó,À¬»ø»ØÊÕ»úÖÆ (GC:Garbage Collecation).ͨ³£ÎÒÃÇʹÓÃnew´´½¨¶ÔÏó,GC¸ºÔð»ØÊÕ¶ÔÏóÕ¼ÓÃÄÚ´æÇøÓò.Òò´ËÁ˽âGC,¿ÉÒÔ¼ÓÉî¶ÔjavascriptÀ¬»ø»ØÊÕ»úÖƵÄÀí ½â¡£
2.Óþֲ¿±äÁ¿ºÍÈ«¾Ö±äÁ¿½âÊÍGC
GCÔÚ»ØÊÕÄÚ´æʱ,Ê×ÏÈ»áÅжϸöÔÏóÊÇ·ñ±»ÆäËü¶ÔÏóÒýÓÃ.ÔÚÈ·¶¨Ã»ÓÐÆäËü¶ÔÏóÒýÓñãÊͷŸöÔÏóÄÚ´æÇøÓò.Òò´ËÈçºÎÈ·¶¨¶ÔÏó²»ÔÙ±»ÒýÓÃÊÇGCµÄ¹Ø¼üËùÔÚ.
<script> function aa(){ this.rr = "µ¯´°"; } function bb(){ this.rr = "µ¯´°"; } var b1; function cc(){ var a1 = new aa(); b1 = new bb(); return b1; } cc(); alert(b1.rr) </script>ÈçÉÏ´úÂëÖУ¬Ö´ÐÐÍêcc()ºóa1±»»ØÊÕÁË,´ËºóÎÒÃÇ¿ÉÒÔͨ¹ýb1.rrµ¯³öÎÄ×Ö´°¿Ú.ÔÚһЩ»ù´¡Êé¼®ÖнâÊÍΪ:a1Ϊ¾Ö²¿±äÁ¿,b1ÊÇÈ«¾Ö±äÁ¿.¾Ö²¿±äÁ¿Ö´ÐÐÍêºó»á±»GC»ØÊÕ.µ«²»È«ÊÇÕâÑù,ÈçÏ´úÂë:
<script> function aa(){ this.rr = "µ¯´°"; } function bb(){ this.rr = "µ¯´°"; } function cc(){ var a1 = new aa(); var b1 = new bb(); return b1; } var b1 = cc(); alert(b1.rr); </script>´Ëʱccº¯ÊýÖÐµÄ a1,b1¶¼ÊǾֲ¿±äÁ¿,µ«ÈÔÈ»»áµ¯³öÎÄ×Ö´°¿Ú.˵Ã÷b1²¢Ã»Óб»GC»ØÊÕ.Òò´ËjavascriptÖоֲ¿±äÁ¿²»ÊÇËùÓÐʱºò¶¼±»GC»ØÊÕµÄ.
3.³éÏóÀí½âGC
GC»ØÊÕ»úÖÆ»¹ÐèÒª½üÒ»²½Á˽⡣ÔÚ´ËʱÒýÈ뼸¸ö¸ÅÄî:Ë«ÏòÁ´±í,×÷ÓÃÓòÁ´,»î¶¯¶ÔÏó(ΪÁË·½±ãÀí½â£¬¼ò»¯ÁËÔÎĵĸÅÄî
[http://softbbs.pconline.com.cn/9497825.html]) , ÆäÖÐË«ÏòÁ´±íÃèÊö¸´ÔÓ¶ÔÏóµÄÉÏϲ㼶¹Øϵ.
×÷ÓÃÓòÁ´Óë»î¶¯¶ÔÏó·Ö±ðÊÇË«ÏòÁ´±íÖеÄij¸ö½Úµã.ÒÔº¯ÊýccΪÀý±äÁ¿²ã¼¶¹ØϵΪ:
window<=>cc<=>a1<=>rr
<=>b1<=>rr
(ÔÎÄÓÐÏêϸ½âÊÍ)ÔÚÖ´ÐÐcc()·½·¨Ê±£¬ÄÚ´æÖбäÁ¿µÄÒýÓùØϵÈçÉÏͼ,ÎÄ×Ö½âÊÍÈçÏÂ:
windowµÄ»î¶¯¶ÔÏó°üÀ¨cc,¼ÙÉèwindowÊǶ¥¼¶¶ÔÏó(ÒòΪÔËÐÐÖв»»á±»»ØÊÕ)
ccµÄ»î¶¯¶ÔÏó°üÀ¨a1ºÍb1,Æä×÷ÓÃÓòÁ´ÊÇwindow
a1µÄ»î¶¯¶ÔÏó°üÀ¨rr,Æä×÷ÓÃÓòÁ´ÊÇcc
b1µÄ»î¶¯¶ÔÏó°üÀ¨rr,Æä×÷ÓÃÓòÁ´ÊÇcc
Ö´ÐÐcc()ʱ£¬ccµÄÖ´Ðл·¾³»á´´½¨Ò»¸ö»î¶¯¶ÔÏóºÍÒ»¸ö×÷ÓÃÓòÁ´.Æä¾Ö²¿±äÁ¿a1,b1¶¼»á¹ÒÔÚccµÄ»î¶¯¶ÔÏóÖÐ.µ±cc()Ö´ÐÐÍê±Ïºó£¬Ö´Ðл·¾³»á³¢
ÊÔ»ØÊջ¶ÔÏóÕ¼ÓõÄÄÚ´æ.µ«Òò¾Ö²¿±äÁ¿b1 ͨ¹ýreturn
b1,ΪÆäÔö¼ÓÁËÒ»Ìõ×÷ÓÃÓòÁ´:window<=>b1<=>rr,ËùÒÔGCÍ£Ö¹¶Ôb1»ØÊÕ.
Òò´ËÈç¹ûÏ뽫һ¸ö¾Ö²¿±äÁ¿/º¯ÊýÌáÉýΪȫ¾ÖµÄ£¬ÎªÆäÔö¼ÓÒ»Ìõ×÷ÓÃÓòÁ´¾ÍOKÁË¡£ ͬʱ¿ØÖƺöÔÏóµÄ×÷ÓÃÓòÁ´Ò²±äµÃÖØÒªÁË.Òò×÷ÓÃÓòÁ´»áÒâÍâµ¼ÖÂGCÎÞ·¨»ØÊÕÄ¿±ê¶ÔÏó.ÀýÈç:
<SCRIPT LANGUAGE="JavaScript"> <!-- //è function cat(name){ var zhuren ; this.name = name; //ÉèÖÃÖ÷ÈË this.addZhuRen = function(zr){ zhuren = zr; } this.getZhuRen = function(){ return zhuren; } } //Ö÷ÈË function zhuren(name){ this.name = name; } //´´½¨Ö÷ÈË: var zr = new zhuren("zhangsan"); //´´½¨Ã¨ var cat1 = new cat("asan"); //ÉèÖøÃèµÄÖ÷ÈË cat1.addZhuRen(zr); //ÊÍ·ÅÖ÷ÈË zr = null ; //´Ë´¦»¹´æÔÚ¶ÔÖ÷È˶ÔÏóµÄÒýÓà alert(cat1.getZhuRen().name) //--> </SCRIPT>
ÍƼöÐÅÏ¢
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- jQuery Tooltips²å¼þ
- jQueryµÄ.bind()¡¢.live()ºÍ.delegate(....
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- Ä㲻ϲ»¶»ðºü£¬µ«ÓÖϲ»¶firebug£¬ÄǾ͸úÎÒÒ»ÆðÀ´ÔÚIEÉÏ....
- ¸ù¾ÝÏÔʾÆ÷·Ö±æÂʵ÷ÕûÒ³ÃæÏÔʾµÄJavascript½Å±¾
- jQuery дµÄ·ÂÐÂÀË΢²© ÏòϹö¶¯Ð§¹û¡¾×ªÔØ¡¿
- ͨÓõÄJqueryÑ¡ÔñÆ÷
- jQuery ½áºÏ Json Ìá½»Êý¾Ýµ½Webservice£¬....
- ×ÔÖÆjQueryÖÇÄÜÌáʾ²å¼þһö
ÈÈÃÅÐÅÏ¢
- 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ÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- js»ñÈ¡srcÖд«µÝµÄ²ÎÊý
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- ÈÃä¯ÀÀÆ÷ÆÁ±ÎµôJavaScriptµÄ³ö´íÌáʾ
- github²»ÄܼÓÔØcss¡¢js½â¾ö°ì·¨
- ÎÒÖªµÀµÄJavaScript -- Éè¼Æģʽ(ÇŽÓ)Ó¦ÓÃÖ® ¨C ....
- 15¸öÖµµÃ¿ª·¢ÈËÔ±¹Ø×¢µÄjQuery¿ª·¢¼¼ÇɺÍÐĵÃ
- dz̸JavascriptÃæÏò¶ÔÏó±à³Ì
- JS¼òµ¥¶¯»·â×°
- JavaScript³õѧÕßӦעÒâµÄÆ߸öϸ½Ú
- jQuery Tooltips²å¼þ
ÆÀÂÛ