<html> <head><title>504 Gateway Time-out</title></head> <body> <center><h1>504 Gateway Time-out</h1></center> <hr><center>nginx</center> </body> </html>

Today, I suddenly found out that del is actually a reference to an object , so is there a way to delete an object directly in Python ?

Mar.28,2021

you are right, " del deletes an object's reference ", which is a good feature of python as a high-level language. Python itself provides a garbage collection (GC) mechanism, which allows users from the tedious manual memory maintenance work, when an object's reference count is 0, the object will be reclaimed by the garbage collection mechanism.

as for the subject said to delete an object, I understand deletion is the free interface provided by the C language to release memory and leave it to the operating system to manage this form of deletion. But it is rather tedious to explain this part.

in Python, there is its own memory management mechanism, which is divided into several levels:

at the lowest level (layer 0) are malloc and free interfaces provided by C language, which belong to the memory management interface provided by the operating system. In layer 1, there is a memory pool to avoid performing a large number of malloc and free operations, otherwise it is easy to cause the operating system to switch frequently between user mode and kernel mode. So python introduces a memory pool mechanism to manage the application and release of small chunks of memory, where the memory after garbage collection is placed on this layer without actually being freed.

since objects are reclaimed on the first layer and not really released, will the memory footprint of python stay high even if it is released after reading a larger file? This was true before the python2.4 version (which seems to be this version, I can't remember). Later, in order to solve this problem, when arena (which can be understood to mean that memory blocks make up an area) are not used, then call free in C language.

to sum up, although the garbage collection mechanism automatically collects objects, its memory is generally not actually freed, but is placed in the memory pool so that the program can create new objects. If you imagine deleting an object directly in the subject, I don't seem to find any API that can free .


  • deleted reference to this object
  • reference count for this object-1
  • if the reference count of this object is 0, it will be garbage collected
  • object is destroyed and its memory is freed

if you explicitly delete an object directly, you should release the memory of the object directly. Consider using Python's garbage collection module.

  Garbage Collector interface . 

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e59788-441ec.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e59788-441ec.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?