I have the following hypothetical Python program that uses some functions of the garbage collector ( documentation ):
import gc
The program prints 0 , which seems strange to me because:
- On first assignment, a
str object is created and referenced by a . - On the second assignment, the second object
str and a and now refers to a . - However, the first
str object was never deleted, because we turned off automatic garbage collection, so it still exists in memory. - Since it exists in memory but is not available, it is similar to the type of object that garbage collection should delete.
I am very grateful for an explanation of why he did not assemble.
PS I know that Python considers some objects (including integers from -3 to 100, as far as I remember) as single, but there are no such specific lines as such objects.
PPS I run it as a whole program, not in the shell
python garbage-collection
Dmitry Torba
source share