Reference Count

sys.getrefcount() method is used to get the reference count for any given object. This value is used by Python as when this value becomes 0, the memory for that particular value is deleted.

Example:

This code prints the reference count of the object a. The reference count of an object is the number of times it is referenced by other objects. An object is garbage collected when its reference count reaches 0, meaning that it is no longer referenced by any other objects

Python3




import sys
a = 'Geeks'
print(sys.getrefcount(a))


Output

4

Python sys Module

The sys module in Python provides various functions and variables that are used to manipulate different parts of the Python runtime environment. It allows operating on the interpreter as it provides access to the variables and functions that interact strongly with the interpreter. Let’s consider the below example.

Similar Reads

Sys Module in Python

Python sys.version...

Input and Output using Python Sys

...

Command Line Arguments

The sys modules provide variables for better control over input or output. We can even redirect the input and output to other devices. This can be done using three variables –...

Exiting the Program

...

Working with Modules

...

Reference Count

...

More Functions in Python sys

Command-line arguments are those which are passed during the calling of the program along with the calling statement. To achieve this using the sys module, the sys module provides a variable called sys.argv. It’s main purpose are:...