Python's memory management

python memory management, from shallow, it can be divided into three in terms of:

1, reference count:

  python reference count in order to track memory object

  When creating an object ie references, when the object is no longer in use, that is, an object reference count is 0, it is garbage collected.

2, garbage collection:

  python can not declare variables in advance the type of direct variable assignment, the garbage collector will check what counts as an object 0, and then clear the space in memory

  There is also a circular garbage collector, the existence of a relationship (a references b, b references a, two circular reference objects, resulting in the reference count is not 0)

 3, memory pool mechanism:

  Each time you create an object in python will apply when small pieces of memory, these pieces are used soon after it was released, because the memory is not to create these objects, and there is no mechanism for a memory pool objects, which results in python at runtime will call malloc and free frequent operation, frequent switching in user mode and kernel mode, such that the efficiency of the program becomes low, so the introduction of memory pool mechanism to manage the application and release small memory.

Guess you like

Origin www.cnblogs.com/a2534786642/p/10947465.html