Garbage collection

Garbage collection is a term used in object orientated programming.

A system to delete objects automatically to free memory.

When you make a program, you may create thousands of objects. All of these objects hold space in your computers memory.

Related course:
Python Beyond the Basics – Object-Oriented Programming

Garbage Collection in Python

Python supports garbage collection, but in some programming languages you have to clean objects yourself.

You can delete objects manually if you want to.

Everything is an object in Python: we define a simple variable x and use that.
During runtime we delete the object and try to output it.

This will output:

In the first 2 lines of the program object x is known. After deletion of the
object x cannot be printed anymore.

Garbage collection is completely automated, you do not have to worry about it.

The __del__() destructor is called just before an object is destroyed.

Previous Post
Next Post

Leave a Reply