SlideShare uma empresa Scribd logo
1 de 6
Heap Generation in .Net Garbage Collection
In the previous blog, we saw a brief introduction on the garbage collection concept in .NET. What is
garbage collection? How does the garbage collector work? How is the memory allocation done?
Structure of the memory heap and advantages of the garbage collector. Over here, we will go into some
more depth and look at a few more things related to this concept.
Let us now learn about the various generations in a managed heap.
Basically, a managed heap is broadly classified into three types of generations. This is done in order to
manage the long lived and the short lived objects in a better manner. While freeing the memory, the
garbage collector first reclaims the short lived objects which consume a small portion of the heap. Then
it moves towards the long lived objects. This is how the garbage collector takes its approach. Now, lets
proceed to the generation types.
http://crbtech.in/Dot-Net-Training/
Generation 0:
This is the first or the latest generation wherein the newly created objects reside. This particular
generation has short lived objects and are collected on a regular basis. The objects which are able to
live in this generation, are transferred to Generation 1. e.g. a temporary object.
Generation 1:
Over here, those objects are present which are long lived and come from the generation 0. The objects
that continue to stay in Generation 1 are sent to Generation 2. This generation acts as a buffer or a
mediator between the long lived objects and the short lived objects.
Generation 2:
This generation has the most longest existing objects. These are promoted from the first generation and
collected rarely.
e.g. An application level object which stores static data and which is available for the duration for
which the process runs.
This was all about the generation types in garbage collection. Now let us see the memory reclaim
process and how does it work.
http://crbtech.in/Dot-Net-Training/
Different Working Phases in Garbage Collector:
1. Marking Phase:
At this stage, the garbage collector enlists the live objects present.
2. Relocating Phase:
In this stage, the collector updates the memory references of those objects which would be compacted.
3. Compacting Phase:
In this stage, the garbage collector obtains the memory previously owned by the dead objects and
compresses the existing objects. This phase shifts the surviving objects towards the older portion of the
memory segment.
A Thing About Garbage Collection Algorithm:
The garbage collector figures out if any object in the memory is dead or not being utilized by the
application. In the event that such object exists, then the memory utilized by these objects can be
recovered. In any case, how does the garbage collector become aware of these objects?
Every single application has an arrangement of roots and these distinguish the storage areas for the
objects on the managed heap.
e.g. All of the global, and static pointers and all the local variable/parameter object pointers on the
string’s stack in the application are considered to be a part of the roots of the application. All in all, any
CPU registers containing pointers to objects in the managed heap are likewise viewed as a part of the
application’s roots.
The rundown of dynamic roots is kept up by the JIT compiler and CLR, and is supplied to the garbage
collector’s algorithm.
The Memory Reclaim Process:
The garbage collector begins to traverse through the roots and make a diagram or a graph of all the
objects that can be reached starting from the roots. The underneath fig. demonstrates a stack with
designated objects. In this memory heap, the application roots straightforwardly allude to the objects
1,3,4,6 and object 3 and 6 refers to the objects 8 and 10. Henceforth all these items will turn into the
part of the live objects chart.
http://crbtech.in/Dot-Net-Training/
The objects which are unreachable from the roots of the application, are taken to be garbage as they are
not located by the application. Over here, objects with the number 2,5,7 and 9 are considered as dead
objects.
http://crbtech.in/Dot-Net-Training/
The garbage collector will clean the dead ones from the memory heap. In the next step, the live objects
will traverse to the older portion of the memory. The Garbage collector also assigns references to the
moving objects within the heap. Root references are also included. This is the general process of
claiming the memory and reusing it.
Hope this article would prove informative for you to understand the concept of garbage collection. You
can join training institutes in pune to enhance your knowledge in .net field.
Related Articles :
• Dot Net Release Silver Light Porting Bridge
• How .Net DLL Works?
http://crbtech.in/Dot-Net-Training/
The garbage collector will clean the dead ones from the memory heap. In the next step, the live objects
will traverse to the older portion of the memory. The Garbage collector also assigns references to the
moving objects within the heap. Root references are also included. This is the general process of
claiming the memory and reusing it.
Hope this article would prove informative for you to understand the concept of garbage collection. You
can join training institutes in pune to enhance your knowledge in .net field.
Related Articles :
• Dot Net Release Silver Light Porting Bridge
• How .Net DLL Works?
http://crbtech.in/Dot-Net-Training/

Mais conteúdo relacionado

Destaque

Mongo dbを知ろう
Mongo dbを知ろうMongo dbを知ろう
Mongo dbを知ろう
CROOZ, inc.
 
知って得するC#
知って得するC#知って得するC#
知って得するC#
Shota Baba
 
DB tech showcase: 噂のMongoDBその用途は?
DB tech showcase: 噂のMongoDBその用途は?DB tech showcase: 噂のMongoDBその用途は?
DB tech showcase: 噂のMongoDBその用途は?
Hiroaki Kubota
 

Destaque (17)

Understanding Garbage Collection
Understanding Garbage CollectionUnderstanding Garbage Collection
Understanding Garbage Collection
 
C#/.NETがやっていること 第二版
C#/.NETがやっていること 第二版C#/.NETがやっていること 第二版
C#/.NETがやっていること 第二版
 
Mongo dbを知ろう
Mongo dbを知ろうMongo dbを知ろう
Mongo dbを知ろう
 
Mongo DBを半年運用してみた
Mongo DBを半年運用してみたMongo DBを半年運用してみた
Mongo DBを半年運用してみた
 
知って得するC#
知って得するC#知って得するC#
知って得するC#
 
chapter - 6.ppt
chapter - 6.pptchapter - 6.ppt
chapter - 6.ppt
 
がっつりMongoDB事例紹介
がっつりMongoDB事例紹介がっつりMongoDB事例紹介
がっつりMongoDB事例紹介
 
はじめてのASP.NET MVC5
はじめてのASP.NET MVC5はじめてのASP.NET MVC5
はじめてのASP.NET MVC5
 
10年前「Microsoftの社員だと思って働け!」と教育されて嫌気がさして出てった人から見た「外の世界」の話 #JCCMVP
10年前「Microsoftの社員だと思って働け!」と教育されて嫌気がさして出てった人から見た「外の世界」の話 #JCCMVP10年前「Microsoftの社員だと思って働け!」と教育されて嫌気がさして出てった人から見た「外の世界」の話 #JCCMVP
10年前「Microsoftの社員だと思って働け!」と教育されて嫌気がさして出てった人から見た「外の世界」の話 #JCCMVP
 
C#や.NET Frameworkがやっていること
C#や.NET FrameworkがやっていることC#や.NET Frameworkがやっていること
C#や.NET Frameworkがやっていること
 
MongoDB〜その性質と利用場面〜
MongoDB〜その性質と利用場面〜MongoDB〜その性質と利用場面〜
MongoDB〜その性質と利用場面〜
 
初心者向けMongoDBのキホン!
初心者向けMongoDBのキホン!初心者向けMongoDBのキホン!
初心者向けMongoDBのキホン!
 
DB tech showcase: 噂のMongoDBその用途は?
DB tech showcase: 噂のMongoDBその用途は?DB tech showcase: 噂のMongoDBその用途は?
DB tech showcase: 噂のMongoDBその用途は?
 
IoT garbage monitoring
IoT garbage monitoringIoT garbage monitoring
IoT garbage monitoring
 
JenkinsとDockerって何が良いの? 〜言うてるオレもわからんわ〜 #jenkinsstudy
JenkinsとDockerって何が良いの? 〜言うてるオレもわからんわ〜 #jenkinsstudyJenkinsとDockerって何が良いの? 〜言うてるオレもわからんわ〜 #jenkinsstudy
JenkinsとDockerって何が良いの? 〜言うてるオレもわからんわ〜 #jenkinsstudy
 
ちゃんとした C# プログラムを書けるようになる実践的な方法~ Visual Studio を使った 高品質・低コスト・保守性の高い開発
ちゃんとした C# プログラムを書けるようになる実践的な方法~ Visual Studio を使った 高品質・低コスト・保守性の高い開発ちゃんとした C# プログラムを書けるようになる実践的な方法~ Visual Studio を使った 高品質・低コスト・保守性の高い開発
ちゃんとした C# プログラムを書けるようになる実践的な方法~ Visual Studio を使った 高品質・低コスト・保守性の高い開発
 
20131026 garbage collection in .net framework
20131026 garbage collection in .net framework20131026 garbage collection in .net framework
20131026 garbage collection in .net framework
 

Último

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Último (20)

Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 

Generation of Heap in .Net Garbage Collection

  • 1. Heap Generation in .Net Garbage Collection In the previous blog, we saw a brief introduction on the garbage collection concept in .NET. What is garbage collection? How does the garbage collector work? How is the memory allocation done? Structure of the memory heap and advantages of the garbage collector. Over here, we will go into some more depth and look at a few more things related to this concept. Let us now learn about the various generations in a managed heap. Basically, a managed heap is broadly classified into three types of generations. This is done in order to manage the long lived and the short lived objects in a better manner. While freeing the memory, the garbage collector first reclaims the short lived objects which consume a small portion of the heap. Then it moves towards the long lived objects. This is how the garbage collector takes its approach. Now, lets proceed to the generation types. http://crbtech.in/Dot-Net-Training/
  • 2. Generation 0: This is the first or the latest generation wherein the newly created objects reside. This particular generation has short lived objects and are collected on a regular basis. The objects which are able to live in this generation, are transferred to Generation 1. e.g. a temporary object. Generation 1: Over here, those objects are present which are long lived and come from the generation 0. The objects that continue to stay in Generation 1 are sent to Generation 2. This generation acts as a buffer or a mediator between the long lived objects and the short lived objects. Generation 2: This generation has the most longest existing objects. These are promoted from the first generation and collected rarely. e.g. An application level object which stores static data and which is available for the duration for which the process runs. This was all about the generation types in garbage collection. Now let us see the memory reclaim process and how does it work. http://crbtech.in/Dot-Net-Training/
  • 3. Different Working Phases in Garbage Collector: 1. Marking Phase: At this stage, the garbage collector enlists the live objects present. 2. Relocating Phase: In this stage, the collector updates the memory references of those objects which would be compacted. 3. Compacting Phase: In this stage, the garbage collector obtains the memory previously owned by the dead objects and compresses the existing objects. This phase shifts the surviving objects towards the older portion of the memory segment. A Thing About Garbage Collection Algorithm: The garbage collector figures out if any object in the memory is dead or not being utilized by the application. In the event that such object exists, then the memory utilized by these objects can be recovered. In any case, how does the garbage collector become aware of these objects? Every single application has an arrangement of roots and these distinguish the storage areas for the objects on the managed heap. e.g. All of the global, and static pointers and all the local variable/parameter object pointers on the string’s stack in the application are considered to be a part of the roots of the application. All in all, any CPU registers containing pointers to objects in the managed heap are likewise viewed as a part of the application’s roots. The rundown of dynamic roots is kept up by the JIT compiler and CLR, and is supplied to the garbage collector’s algorithm. The Memory Reclaim Process: The garbage collector begins to traverse through the roots and make a diagram or a graph of all the objects that can be reached starting from the roots. The underneath fig. demonstrates a stack with designated objects. In this memory heap, the application roots straightforwardly allude to the objects 1,3,4,6 and object 3 and 6 refers to the objects 8 and 10. Henceforth all these items will turn into the part of the live objects chart. http://crbtech.in/Dot-Net-Training/
  • 4. The objects which are unreachable from the roots of the application, are taken to be garbage as they are not located by the application. Over here, objects with the number 2,5,7 and 9 are considered as dead objects. http://crbtech.in/Dot-Net-Training/
  • 5. The garbage collector will clean the dead ones from the memory heap. In the next step, the live objects will traverse to the older portion of the memory. The Garbage collector also assigns references to the moving objects within the heap. Root references are also included. This is the general process of claiming the memory and reusing it. Hope this article would prove informative for you to understand the concept of garbage collection. You can join training institutes in pune to enhance your knowledge in .net field. Related Articles : • Dot Net Release Silver Light Porting Bridge • How .Net DLL Works? http://crbtech.in/Dot-Net-Training/
  • 6. The garbage collector will clean the dead ones from the memory heap. In the next step, the live objects will traverse to the older portion of the memory. The Garbage collector also assigns references to the moving objects within the heap. Root references are also included. This is the general process of claiming the memory and reusing it. Hope this article would prove informative for you to understand the concept of garbage collection. You can join training institutes in pune to enhance your knowledge in .net field. Related Articles : • Dot Net Release Silver Light Porting Bridge • How .Net DLL Works? http://crbtech.in/Dot-Net-Training/