In python there is an Entity that is called the GarbageCollector (GC) which takes care of "storing" the deleted objects every object, you can read more in the docs for details.
The values of your program’s objects are stored in memory for quick access. In many programming languages, a variable in your program code is simply a pointer to the address of the object in memory. When a variable is used in a program, the process will read the value from memory and operate on it. In early programming languages, developers were responsible for all memory management in their programs. This meant before creating a list or an object, you first needed to allocate the memory for your variable. After you were done with your variable, you then needed to deallocate it to “free” that memory for other users. Python's garbage collector is an automatic memory allocator, removing the need to do it yourself.
Using the __del__
property of an object will only detach the variable's name to the object itself, but the object won't actually be flushed from the memory, it will be caught by the garbage collector, which will allow the object to be flushed if the GC find it's necessary.
To flush the garbage collector, you can use python's gc
module. the collect()
method flushes the memory of the garbage collector.
import gc
gc.collect()
view this thread for more info on garbage collection.