ÄúÏÖÔÚµÄλÖ㺠Ö÷Ò³ > ÉÏλ»ú¼¼Êõ > python > ΪʲôPythonҪʹÓÃÓÐÃ÷ÏÔȱÏݵÄÒýÓüÆÊý¶ø²»ÊÇÏñJavaScriptÒ»Ñù
±¾ÎÄËùÊô±êÇ©:
Ϊ±¾ÎÄ´´Á¢¸ö±êÇ©°É:

ΪʲôPythonҪʹÓÃÓÐÃ÷ÏÔȱÏݵÄÒýÓüÆÊý¶ø²»ÊÇÏñJavaScriptÒ»Ñù

À´Ô´£ºÍøÂçÕûÀí ÍøÂçÓû§·¢²¼£¬ÈçÓаæÈ¨ÁªÏµÍø¹Üɾ³ý¡¡2018-08-13¡¡

ÕâÊÇÒ»ÖÖÉè¼ÆÈ¡Éá¡£ÓÃCPythonµÄ´ó¼Ò¸ßÐ˾ͺÃß¡£
ÆäËüPythonʵÏÖÓÐÐí¶à²»ÓÃÒýÓüÆÊýµÄ£¬²»¸ßÐË¿ÉÒÔÓÃËüÃÇ£¨ÌÓ

ÁíÍâCPythonµÄÒýÓüÆÊýÊÇÓÐmark-sweep±¸·ÝµÄ£¬²»ÅÂÑ­»·ÒýÓá£
¹ÙÍø½âÊÍÁËÕâ¸öÑ¡Ôñ£¨µ«ÆäʵҲû˵ʲô¡­£©£ºhttps://docs.python.org/2/faq/design.html#how-does-python-manage-memory

The details of Python memory management depend on the implementation. The standard C implementation of Python uses reference counting to detect inaccessible objects, and another mechanism to collect reference cycles, periodically executing a cycle detection algorithm which looks for inaccessible cycles and deletes the objects involved. The gc module provides functions to perform a garbage collection, obtain debugging statistics, and tune the collector¡¯s parameters.

In the absence of circularities and tracebacks, Python programs do not need to manage memory explicitly.

Why doesn¡¯t Python use a more traditional garbage collection scheme? For one thing, this is not a C standard feature and hence it¡¯s not portable. (Yes, we know about the Boehm GC library. It has bits of assembler code for most common platforms, not for all of them, and although it is mostly transparent, it isn¡¯t completely transparent; patches are required to get Python to work with it.)
...
Traditional GC also becomes a problem when Python is embedded into other applications. While in a standalone Python it¡¯s fine to replace the standard malloc() and free() with versions provided by the GC library, an application embedding Python may want to have its own substitute for malloc() and free(), and may not want Python¡¯s. Right now, Python works with anything that implements malloc() and free() properly.

È»ºóÇë¿´ÕâÆªÎÄÕ½éÉܽÏеÄPythonµÄ¡°mark-swep GC¡±Æäʵ»¹ÊÇ¡°·Ö´úʽ¡±µÄ£ºhttp://patshaughnessy.net/2013/10/30/generational-gc-in-python-and-ruby

È»ºó¾ÍÊÇJavaScriptÒ²²»Ò»¶¨ÊÇÓÃmark-sweepµÄ¡­ÓïÑԹ淶ûÕâô¹æ¶¨£¬Êµ¼ÊʵÏÖÒ²²»È«ÊÇÓÃmark-sweep¡£

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ²é¿´ÆÀÂÛ »Ø¸´



ǶÈëʽ½»Á÷ÍøÖ÷Ò³ > ÉÏλ»ú¼¼Êõ > python > ΪʲôPythonҪʹÓÃÓÐÃ÷ÏÔȱÏݵÄÒýÓüÆÊý¶ø²»ÊÇÏñJavaScriptÒ»Ñù
 È»ºó ÒýÓà ¼ÆÊý

"ΪʲôPythonҪʹÓÃÓÐÃ÷ÏÔȱÏݵÄÒýÓüÆÊý¶ø²»ÊÇÏñJavaScriptÒ»Ñù"µÄÏà¹ØÎÄÕÂ

ÍøÕ¾µØÍ¼

Χ¹Û()