
On Thu, 12 Mar 2020 at 19:05, Chris Angelico <rosuav@gmail.com> wrote:
The action of deleting a *name* is not the same as disposing of an *object*. You can consider "del x" to be very similar to "x = None", except that instead of rebinding to some other object, it unbinds x altogether.
Exactly. But if `x = None` will return the previous value of x, the refcount of the object will be not decreased, and Python does not free the object memory. An example: (venv) marco@buzz:~/sources$ python Python 3.8.2 (tags/v3.8.2-dirty:7b3ab5921f, Mar 1 2020, 16:16:55) [GCC 9.2.0] on linux Type "help", "copyright", "credits" or "license" for more information.
from sys import getrefcount a = "nfnjgjsbsjbjbsjlbslj" getrefcount(a) 2 a 'nfnjgjsbsjbjbsjlbslj' getrefcount(a) 3