> For the complete documentation index, see [llms.txt](https://gyansetu-python.gitbook.io/python-programming/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gyansetu-python.gitbook.io/python-programming/oops/garbage-collection.md).

# Destructors

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.

Example 1:

```python
# Python program to illustrate destructor 
class Employee: 

	# Initializing 
	def __init__(self): 
		print('Employee created.') 

	# Deleting (Calling destructor) 
	def __del__(self): 
		print('Destructor called, Employee deleted.') 

obj = Employee() 
del obj 
```

Employee created.&#x20;

Destructor called, Employee deleted.

**Example 2:**

```python
# Python program to illustrate destructor 

class Employee: 

	# Initializing 
	def __init__(self): 
		print('Employee created') 

	# Calling destructor 
	def __del__(self): 
		print("Destructor called") 

def Create_obj(): 
	print('Making Object...') 
	obj = Employee() 
	print('function end...') 
	return obj 

print('Calling Create_obj() function...') 
obj = Create_obj()
del obj 
print('Program End...') 

```

Calling Create\_obj() function...&#x20;

Making Object...&#x20;

Employee created function end...&#x20;

Destructor called&#x20;

Program End...
