SlideShare une entreprise Scribd logo
1  sur  13
GAURAV
19mslsbf03
M.Sc Life science(Bioinformatics)
Memory management
 Memory management is the process of
efficiently allocating, de-allocating, and
coordinating memory so that all the
different processes run smoothly and
can optimally access different system
resources.
 Memory management also involves
cleaning memory of objects that are no
longer being accessed.
 In Python, the memory manager is responsible for these
kinds of tasks by periodically running to clean up, allocate,
and manage the memory.
 Unlike C, Java, and other programming languages, Python
manages objects by using reference counting.
 This means that the memory manager keeps track of the
number of references to each object in the program.
 When an object's reference count drops to zero, which means
the object is no longer being used, the garbage collector (part
of the memory manager) automatically frees the memory
from that particular object.
 The user need not to worry about memory management as
the process of allocation and de-allocation of memory is
fully automatic. The reclaimed memory can be used by other
objects.
Python Objects in Memory
 Each variable in Python acts as an
object. Objects can either be simple
(containing numbers, strings, etc.) or
containers (dictionaries, lists, or user
defined classes).
 Furthermore, Python is a dynamically
typed language which means that we do
not need to declare the variables or their
types before using them in a program.
If you look at the first 2 lines of the above program, object x is
known. When we delete the object x and try to use it, we get
an error stating that the variable x is not defined.
How python objects store in
memory?
Names
References
objects
 What is a reference?
A name or a container object pointing at
another object.
 What is a reference count?
Reference counting is a simple technique
in which objects are allocated when there is
reference to them in a program
To increase reference count
X
300
+1
References: 1
X
Y
300
+1
References: 2
+1
What does del do?
The del statement doesn’t delete objects. It:
• removes that name as a reference to that
object
• reduces the ref count by 1
X = 300
Y = 300
del X
X
Y
300
References: 1
Decrease reference count
Ref count: +1
‘seven’ is out of
scope
Ref count: -1
What is Garbage
Collection?
 A way for a program to automatically release
memory when the object taking up that space is no
longer in use.
 The Python Garbage Collector (GC) runs during the
program execution and is triggered if the reference
count reduces to zero.
 The memory is a heap that contains objects and
other data structures used in the program. The
allocation and de-allocation of this heap space is
controlled by the Python Memory manager through
the use of API functions.
 Two main types of garbage collection:
1. Reference counting
2. Tracing
References
 https://www.slideshare.net/nnja/memory-
management-in-python-the-basics
 https://stackabuse.com/basics-of-
memory-management-in-python/
 https://www.youtube.com/watch?v=3pXq
uKQf2qk
 codes were written in Python 3
Memory management in python

Contenu connexe

Tendances

Tendances (20)

Python Basics
Python BasicsPython Basics
Python Basics
 
Introduction To Python | Edureka
Introduction To Python | EdurekaIntroduction To Python | Edureka
Introduction To Python | Edureka
 
Generators In Python
Generators In PythonGenerators In Python
Generators In Python
 
C functions
C functionsC functions
C functions
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
 
Python ppt
Python pptPython ppt
Python ppt
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
Python basics
Python basicsPython basics
Python basics
 
Syntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address CodeSyntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address Code
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
 
OOP in C++
OOP in C++OOP in C++
OOP in C++
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter Notebooks
 
Python PPT
Python PPTPython PPT
Python PPT
 

Similaire à Memory management in python

Similaire à Memory management in python (20)

Kripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptx
Kripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptxKripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptx
Kripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptx
 
C++
C++C++
C++
 
Unit 5
Unit 5Unit 5
Unit 5
 
Chapter1 introduction
Chapter1 introductionChapter1 introduction
Chapter1 introduction
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Introduction to Artificial Intelligence...pptx
Introduction to Artificial Intelligence...pptxIntroduction to Artificial Intelligence...pptx
Introduction to Artificial Intelligence...pptx
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Paradigms.pptx
Paradigms.pptxParadigms.pptx
Paradigms.pptx
 
My c++
My c++My c++
My c++
 
Interview preparation for programming.pptx
Interview preparation for programming.pptxInterview preparation for programming.pptx
Interview preparation for programming.pptx
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2
 
Python-Classes.pptx
Python-Classes.pptxPython-Classes.pptx
Python-Classes.pptx
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
Chapter1
Chapter1Chapter1
Chapter1
 
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdfChapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdf
 
DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS
 
Technical_Interview_Questions.pdf
Technical_Interview_Questions.pdfTechnical_Interview_Questions.pdf
Technical_Interview_Questions.pdf
 
Data structures using C
Data structures using CData structures using C
Data structures using C
 

Plus de Gaurav Aggarwal

Nucleus
NucleusNucleus

Plus de Gaurav Aggarwal (12)

Optimal gene circuit design
Optimal gene circuit designOptimal gene circuit design
Optimal gene circuit design
 
Ethics in assisted reproductive technologies
Ethics in assisted reproductive technologiesEthics in assisted reproductive technologies
Ethics in assisted reproductive technologies
 
Descriptors
DescriptorsDescriptors
Descriptors
 
Apriori algorithm
Apriori algorithmApriori algorithm
Apriori algorithm
 
Epidemiology, Genetic Recombination, and Pathogenesis of Coronaviruses
Epidemiology, Genetic Recombination, and Pathogenesis of CoronavirusesEpidemiology, Genetic Recombination, and Pathogenesis of Coronaviruses
Epidemiology, Genetic Recombination, and Pathogenesis of Coronaviruses
 
Introduction to numpy
Introduction to numpyIntroduction to numpy
Introduction to numpy
 
Sequence analysis
Sequence analysisSequence analysis
Sequence analysis
 
Immunity to microbes
Immunity to microbesImmunity to microbes
Immunity to microbes
 
Challenges and drawbacks of drug discovery and development
Challenges and drawbacks of drug discovery and developmentChallenges and drawbacks of drug discovery and development
Challenges and drawbacks of drug discovery and development
 
Nucleus
NucleusNucleus
Nucleus
 
Forces stabilizing nucleic acid structure
Forces stabilizing nucleic acid structureForces stabilizing nucleic acid structure
Forces stabilizing nucleic acid structure
 
Enzyme catalysis
Enzyme catalysisEnzyme catalysis
Enzyme catalysis
 

Dernier

一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
pyhepag
 
Data Analytics for Digital Marketing Lecture for Advanced Digital & Social Me...
Data Analytics for Digital Marketing Lecture for Advanced Digital & Social Me...Data Analytics for Digital Marketing Lecture for Advanced Digital & Social Me...
Data Analytics for Digital Marketing Lecture for Advanced Digital & Social Me...
Valters Lauzums
 
一比一原版麦考瑞大学毕业证成绩单如何办理
一比一原版麦考瑞大学毕业证成绩单如何办理一比一原版麦考瑞大学毕业证成绩单如何办理
一比一原版麦考瑞大学毕业证成绩单如何办理
cyebo
 
一比一原版西悉尼大学毕业证成绩单如何办理
一比一原版西悉尼大学毕业证成绩单如何办理一比一原版西悉尼大学毕业证成绩单如何办理
一比一原版西悉尼大学毕业证成绩单如何办理
pyhepag
 
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
pyhepag
 
Exploratory Data Analysis - Dilip S.pptx
Exploratory Data Analysis - Dilip S.pptxExploratory Data Analysis - Dilip S.pptx
Exploratory Data Analysis - Dilip S.pptx
DilipVasan
 
Fuzzy Sets decision making under information of uncertainty
Fuzzy Sets decision making under information of uncertaintyFuzzy Sets decision making under information of uncertainty
Fuzzy Sets decision making under information of uncertainty
RafigAliyev2
 

Dernier (20)

2024 Q1 Tableau User Group Leader Quarterly Call
2024 Q1 Tableau User Group Leader Quarterly Call2024 Q1 Tableau User Group Leader Quarterly Call
2024 Q1 Tableau User Group Leader Quarterly Call
 
Supply chain analytics to combat the effects of Ukraine-Russia-conflict
Supply chain analytics to combat the effects of Ukraine-Russia-conflictSupply chain analytics to combat the effects of Ukraine-Russia-conflict
Supply chain analytics to combat the effects of Ukraine-Russia-conflict
 
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
 
Easy and simple project file on mp online
Easy and simple project file on mp onlineEasy and simple project file on mp online
Easy and simple project file on mp online
 
Data Analytics for Digital Marketing Lecture for Advanced Digital & Social Me...
Data Analytics for Digital Marketing Lecture for Advanced Digital & Social Me...Data Analytics for Digital Marketing Lecture for Advanced Digital & Social Me...
Data Analytics for Digital Marketing Lecture for Advanced Digital & Social Me...
 
一比一原版麦考瑞大学毕业证成绩单如何办理
一比一原版麦考瑞大学毕业证成绩单如何办理一比一原版麦考瑞大学毕业证成绩单如何办理
一比一原版麦考瑞大学毕业证成绩单如何办理
 
basics of data science with application areas.pdf
basics of data science with application areas.pdfbasics of data science with application areas.pdf
basics of data science with application areas.pdf
 
一比一原版西悉尼大学毕业证成绩单如何办理
一比一原版西悉尼大学毕业证成绩单如何办理一比一原版西悉尼大学毕业证成绩单如何办理
一比一原版西悉尼大学毕业证成绩单如何办理
 
Atlantic Grupa Case Study (Mintec Data AI)
Atlantic Grupa Case Study (Mintec Data AI)Atlantic Grupa Case Study (Mintec Data AI)
Atlantic Grupa Case Study (Mintec Data AI)
 
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
 
2024 Q2 Orange County (CA) Tableau User Group Meeting
2024 Q2 Orange County (CA) Tableau User Group Meeting2024 Q2 Orange County (CA) Tableau User Group Meeting
2024 Q2 Orange County (CA) Tableau User Group Meeting
 
How I opened a fake bank account and didn't go to prison
How I opened a fake bank account and didn't go to prisonHow I opened a fake bank account and didn't go to prison
How I opened a fake bank account and didn't go to prison
 
Generative AI for Trailblazers_ Unlock the Future of AI.pdf
Generative AI for Trailblazers_ Unlock the Future of AI.pdfGenerative AI for Trailblazers_ Unlock the Future of AI.pdf
Generative AI for Trailblazers_ Unlock the Future of AI.pdf
 
Data Visualization Exploring and Explaining with Data 1st Edition by Camm sol...
Data Visualization Exploring and Explaining with Data 1st Edition by Camm sol...Data Visualization Exploring and Explaining with Data 1st Edition by Camm sol...
Data Visualization Exploring and Explaining with Data 1st Edition by Camm sol...
 
Artificial_General_Intelligence__storm_gen_article.pdf
Artificial_General_Intelligence__storm_gen_article.pdfArtificial_General_Intelligence__storm_gen_article.pdf
Artificial_General_Intelligence__storm_gen_article.pdf
 
Exploratory Data Analysis - Dilip S.pptx
Exploratory Data Analysis - Dilip S.pptxExploratory Data Analysis - Dilip S.pptx
Exploratory Data Analysis - Dilip S.pptx
 
AI Imagen for data-storytelling Infographics.pdf
AI Imagen for data-storytelling Infographics.pdfAI Imagen for data-storytelling Infographics.pdf
AI Imagen for data-storytelling Infographics.pdf
 
Fuzzy Sets decision making under information of uncertainty
Fuzzy Sets decision making under information of uncertaintyFuzzy Sets decision making under information of uncertainty
Fuzzy Sets decision making under information of uncertainty
 
社内勉強会資料  Mamba - A new era or ephemeral
社内勉強会資料   Mamba - A new era or ephemeral社内勉強会資料   Mamba - A new era or ephemeral
社内勉強会資料  Mamba - A new era or ephemeral
 
Machine Learning for Accident Severity Prediction
Machine Learning for Accident Severity PredictionMachine Learning for Accident Severity Prediction
Machine Learning for Accident Severity Prediction
 

Memory management in python

  • 2. Memory management  Memory management is the process of efficiently allocating, de-allocating, and coordinating memory so that all the different processes run smoothly and can optimally access different system resources.  Memory management also involves cleaning memory of objects that are no longer being accessed.
  • 3.  In Python, the memory manager is responsible for these kinds of tasks by periodically running to clean up, allocate, and manage the memory.  Unlike C, Java, and other programming languages, Python manages objects by using reference counting.  This means that the memory manager keeps track of the number of references to each object in the program.  When an object's reference count drops to zero, which means the object is no longer being used, the garbage collector (part of the memory manager) automatically frees the memory from that particular object.  The user need not to worry about memory management as the process of allocation and de-allocation of memory is fully automatic. The reclaimed memory can be used by other objects.
  • 4. Python Objects in Memory  Each variable in Python acts as an object. Objects can either be simple (containing numbers, strings, etc.) or containers (dictionaries, lists, or user defined classes).  Furthermore, Python is a dynamically typed language which means that we do not need to declare the variables or their types before using them in a program.
  • 5. If you look at the first 2 lines of the above program, object x is known. When we delete the object x and try to use it, we get an error stating that the variable x is not defined.
  • 6. How python objects store in memory? Names References objects
  • 7.  What is a reference? A name or a container object pointing at another object.  What is a reference count? Reference counting is a simple technique in which objects are allocated when there is reference to them in a program
  • 8. To increase reference count X 300 +1 References: 1 X Y 300 +1 References: 2 +1
  • 9. What does del do? The del statement doesn’t delete objects. It: • removes that name as a reference to that object • reduces the ref count by 1 X = 300 Y = 300 del X X Y 300 References: 1
  • 10. Decrease reference count Ref count: +1 ‘seven’ is out of scope Ref count: -1
  • 11. What is Garbage Collection?  A way for a program to automatically release memory when the object taking up that space is no longer in use.  The Python Garbage Collector (GC) runs during the program execution and is triggered if the reference count reduces to zero.  The memory is a heap that contains objects and other data structures used in the program. The allocation and de-allocation of this heap space is controlled by the Python Memory manager through the use of API functions.  Two main types of garbage collection: 1. Reference counting 2. Tracing