Memory management (garbage collection)
-
Object Category:
-
Fixed-length: int / float
-
A plurality of elements: str / list / dict / set / tuple
typedef struct {
PyObject ob_base;
Py_ssize_t ob_size; /* Number of items in variable part */
} PyVarObject;
-
-
Memory management
-
Based reference counter
def func (): each created object, the open space in the memory, the reference counter by default. 1; a = 123 create a variable opening up a point to the original memory, the reference count + 1'd; B = a FUNC ( ) when the reference counter is 0, it indicates that the garbage can be recycled.
-
Circulation problems cited
When an object is created for the Python str / list / dict / set / tuple class, the object will be placed in a doubly linked list.
A = "asdf"
B = [11,22]
C = { 'K1': 123} If the object list 700 is reached, the elements on all the doubly linked list is scanned, if there is a circular reference, the two are -1, and finally scanned, all the elements of the list into two: 1. the reference counter 0 objects recovered. 2. the object reference counter is not 0, it will be a doubly linked list into another (a total of three lists).
-