i
Python functionality and evolution
Installing Python (windows and Ubuntu)
IDLE (Integrated Development and Learning Environment)
Write the first python program and execute it
Keywords in Python
Identifiers in Python
Indentation in Python
Comments in Python
Multi-line Comments in Python
Getting user input
Python Function
Calling a function
Arguments in Function
Scope of Variables
Modules in Python
The PYTHON PATH-Variable
Python File Open
Python File Opening Modes
The file-Object-Attributes
Python File Close() Method
Python File Read/Write
Python File Position
Renaming and Deleting Files in Python
Python Directory Methods
File/Directory Methods
Exceptions in Python
The try-finally Clause
The argument of Exception
Raising Exceptions
Python Built-in Exceptions
Python OOPs Concepts
Python Classes/Objects
Creating Instance Objects
Accessing Attributes
Built-In Class Attributes
Garbage Collection
Python Inheritance
Overriding Methods
Method overriding
Data Hiding
Regular Expression
The match function
The search function
Match Object Methods & Description
Matching or Searching
Search or Replace
Regular Expression Modifiers / Option Flags
Grouping with Parentheses
Python Socket Programming
Python Socket Server
Python Socket Client
Send Data Between Clients
Python Socket or Server
Python Socket Clients
Points to ponder
Python deletes unneeded objects automatically free memory space,process by which Python periodically reclaims blocks of memory that no longer are used called Garbage-Collection.
Python garbage-collector runs during program execution and is triggered, when object's reference count reaches zero. An object's reference count changes as number of aliases that point to their changes.
An object's reference count increases when it assigns a new name or placed in container like list, tuple, or dictionary. The object reference count decreases when it deleted with del, its reference reassigned, or its reference goes out of scope. When object's reference count reaches zero python collects automatically.
x = 40 # Create object <40>
y = x # Increase ref. count of <40>
z = [y] # Increase ref. count of <40>
del x # Decrease ref. count of <40>
y = 100 # Decrease ref. count of <40>
z[0] = -1 # Decrease ref. count of <40>
You normally will not notice when garbage collector destroys orphaned instance and reclaims its space. But a class can implement special method __del__(), called a destructor, that is invoked when instance is about to be destroyed. This method might used to clean up any non-memory resources used by instance.
Example
This __del__() destructor prints class name of an instance that about to be destroyed −
Live Demo
Output:
3083401323 3083401323 3083401323
Point now destroyed
Don't miss out!