Like any other programming language, concept of variable is connected to memory allocation. Variable is the storage space which can store the values, as per its behavior.
For instance, let us consider a statement, a = 20, here memory is allocated with name ‘a’ and value 20 is stored in it. In the similar manner, for every variable, a separate memory space is allocated in the heap memory area.
Do you know ?
Python Programming follows the approach of Duck Typing.
Using Duck Typing, we do not check types at all, we check for the presence of a given method or attribute.
The name Duck Typing comes from the phrase:
“If it looks like a duck and quacks like a duck, it’s a duck.”
Garbage Collection is a form of automatic memory management. The garbage collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program. Module that represents the garbage collector is named as ‘gc‘. Garbage collector aims to identify the reference cycles. Reference cycle is the cycle of references from initial object to final object. It is used to identify reference count of any object. When any object is referenced, its reference count is set to 1. Garbage collector will only remove the objects if its reference count is 0.
Garbage collector runs automatically. Python schedules the garbage collector on the basis of threshold value. It can be known with the help of get_threshold() of gc module. However, in some cases, where reference cycle is not found, it is suggested to run gc manually using collect() method.
That’s all, see you in the next lecture.