EC Lecture Notes - Lecture 2: Circular Reference, Init

9 views2 pages

Document Summary

Destructors are called when an object gets destroyed. In python, destructors are not needed as much needed in. C++ because python has a garbage collector that handles memory management automatically. The __del__() method is a known as a destructor method in python. It is called when all references to the object have been deleted i. e when an object is garbage collected. Note : a reference to objects is also deleted when the object goes out of reference or when the program ends. Example 1 : here is the simple example of destructor. By using del keyword we deleted the all references of object. # deleting (calling destructor) def __del__(self): print("destructor called, employee deleted. ") obj = employee() del obj. Note : the destructor was called after the program ended or when all the references to object are deleted i. e when the reference count becomes zero, not when object went out of scope.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents