ÔõÑù½â¾öLinuxϵͳÖзºÆðµÄÄÚ´æ×ß©ÎÊÌâ
ÔõÑù½â¾ölinuxϵͳÖзºÆðµÄÄÚ´æ×ß©ÎÊÌâ
Ëæ×ÅÅÌËã»úϵͳµÄÉú³¤£¬ÄÚ´æ×ß©ÎÊÌâÖð½¥³ÉΪ¿ª·¢Ö°Ô±ÐèÒª¹Ø×¢µÄÒ»¸öÖ÷Òª·½Ãæ¡£ÌØÊâÊÇÔÚLinuxϵͳÖУ¬ÄÚ´æ×ß©ÎÊÌâÔ½·¢³£¼û¡£±¾ÎĽ«ÏÈÈÝÄÚ´æ×ß©µÄÔµ¹ÊÔÓɺÍÓ°Ï죬²¢ÌṩһЩ½â¾öÄÚ´æ×ß©ÎÊÌâµÄÒªÁì¡£
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÏàʶʲôÊÇÄÚ´æ×ß©¡£¼ò¶øÑÔÖ®£¬ÄÚ´æ×ß©ָµÄÊÇÔÚ³ÌÐòÔËÐÐʱÉêÇëµÄÄÚ´æ¿Õ¼äûÓб»×¼È·ÊÍ·Å£¬Ö±µ½³ÌÐò¿¢Ê²ŻáÊÍ·Å£¬µ¼ÖÂÄÚ´æÎÞ·¨Ôٴα»Ê¹Óᣵ±ÄÚ´æ×ß©ÎÊÌâÔ½À´Ô½ÑÏÖØʱ£¬ÏµÍ³µÄ¿ÉÓÃÄÚ´æ»áÔ½À´Ô½ÉÙ£¬×îÖÕµ¼ÖÂϵͳ±ÀÀ£»ò±äµÃ·Ç³£»ºÂý¡£
ÄÇô£¬ÄÚ´æ×ß©ÎÊÌâÊÇÔõÑù±¬·¢µÄÄØ£¿Ê×ÏÈ£¬´úÂëÖеĹýʧʹÓö¯Ì¬ÄÚ´æ·ÖÅɺ¯Êý£¨Èçmalloc¡¢calloc¡¢realloc£©¶øδ׼ȷÊÍ·ÅÕâЩÄÚ´æ¡£Æä´Î£¬±£´æÖ¸ÕëÎÊÌ⣬µ¼Ö³ÌÐòÎÞ·¨×¼È·ÊÍ·ÅÄÚ´æ¡£±ðµÄ£¬Ä³Ð©º¯Êý¿ÉÄܻᵼÖÂÄÚ´æ×ß©£¬Èçδ¹Ø±ÕµÄÎļþÖ¸ÕëºÍÍøÂçÌ×½Ó×ֵȡ£
ÏÂÃæÊÇһЩ½â¾öÄÚ´æ×ß©ÎÊÌâµÄÒªÁ죺
ʹÓúÏÊʵÄÄÚ´æ·ÖÅɺÍÊͷź¯Êý£ºÔÚʹÓÃmalloc¡¢calloc¡¢reallocº¯Êý·ÖÅÉÄÚ´æʱ£¬ÒªÈ·±£ÔÚ²»ÐèҪʹÓøÃÄÚ´æʱʵʱÊÍ·Å¡£¿ÉÒÔʹÓÃfreeº¯ÊýÀ´ÊͷŶ¯Ì¬·ÖÅɵÄÄÚ´æ¡£
¼ì²éÖ¸ÕëÎÊÌ⣺ÔÚ³ÌÐòÖÐÌØÊâÊÇʹÓÃÖ¸Õëʱ£¬Òª×¢ÖØÖ¸ÕëµÄ׼ȷÐÔ¡£È·±£ÔÚʹÓÃÍêÖ¸Õëºó½«ÆäÖÃΪNULL£¬×èÖ¹Ò°Ö¸ÕëµÄ·ºÆð¡£
ʹÓÃÀ¬»ø½ÓÄÉ»úÖÆ£ºÀ¬»ø½ÓÄÉ£¨Garbage collection£©ÊÇÒ»ÖÖ×Ô¶¯ÄÚ´æÖÎÀíÊÖÒÕ£¬¿ÉïÔÌÄÚ´æ×ß©ÎÊÌ⡣ͨ¹ýÀ¬»ø½ÓÄÉ»úÖÆ£¬ÏµÍ³»á×Ô¶¯¼ì²âºÍ½ÓÄÉδʹÓõÄÄÚ´æ¿Õ¼ä¡£
ʹÓÃÄÚ´æ×ß©¼ì²â¹¤¾ß£ºLinuxϵͳÌṩÁËһЩ¹¤¾ß¿ÉÒÔ×ÊÖú¼ì²âÄÚ´æ×ß©ÎÊÌâ¡£ÀýÈ磬ValgrindÊÇÒ»¸öÆÕ±éʹÓõÄÄÚ´æ×ß©¼ì²â¹¤¾ß£¬Ëü¿ÉÒÔͨ¹ý¼ì²é³ÌÐòµÄÄÚ´æ·ÖÅɺÍÊÍ·ÅÀ´¼ì²âDZÔÚµÄÄÚ´æ×ß©¡£
×¢ÖعرÕÎļþºÍÍøÂçÅþÁ¬£ºÔÚ³ÌÐòÖУ¬·¿ªµÄÎļþºÍÍøÂçÅþÁ¬Ò²»áÕ¼ÓÃÄÚ´æ×ÊÔ´¡£Òò´Ë£¬ÔÚ²»ÐèҪʹÓÃËüÃÇʱӦʵʱ¹Ø±Õ£¬×èÖ¹×ÊÔ´ÆÌÕźÍÄÚ´æ×ß©¡£
³ýÁËÉÏÊöÒªÁ죬ÉÐÓÐһЩÆäËû½¨Òé¿ÉÒÔ×ÊÖúïÔÌÄÚ´æ×ß©ÎÊÌâ¡£ÀýÈ磬±àдÇåÎú¡¢¾«Á·µÄ´úÂ룬×èÖ¹ÖØ´óµÄǶÌ׺ÍÖظ´µÄ´úÂ룻ºÏÀíʹÓûº´æºÍÔÝʱ±äÁ¿£¬×èֹ̫¹ýʹÓÃÄÚ´æ×ÊÔ´¡£
×ÜÖ®£¬LinuxϵͳÖеÄÄÚ´æ×ß©ÎÊÌâ»á¸øϵͳµÄÐÔÄܺÍÎȹÌÐÔ´øÀ´ºÜ´óµÄÓ°Ï졣ΪÏàʶ¾öÕâ¸öÎÊÌ⣬¿ª·¢Ö°Ô±Ó¦×¢ÖØ´úÂëÖеÄÄÚ´æ·ÖÅɺÍÊÍ·Å£¬²¢Ê¹Óù¤¾ßºÍÊÖÒÕÀ´¼ì²âºÍÐÞ¸´Ç±ÔÚµÄÄÚ´æ×ß©¡£Ö»ÓÐÕâÑù£¬ÎÒÃDzŻªÈ·±£³ÌÐòÔÚºã¾ÃÔËÐÐÀú³ÌÖв»»áÏûºÄ¹ý¶àµÄÄÚ´æ×ÊÔ´£¬¼á³ÖϵͳµÄ¸ßЧºÍÎȹÌÔËÐС£
ÒÔÉϾÍÊÇÔõÑù½â¾öLinuxϵͳÖзºÆðµÄÄÚ´æ×ß©ÎÊÌâµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡