• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Garbage Collection In  Micorosoft
 

Garbage Collection In Micorosoft

on

  • 1,399 views

Dscribes about in and out of Garbage Collector. How the GC fits in .Net framework, its algorithm and some tips to being friendly with GC. Along with basic understanding of memory management in .Net ...

Dscribes about in and out of Garbage Collector. How the GC fits in .Net framework, its algorithm and some tips to being friendly with GC. Along with basic understanding of memory management in .Net (Stack vs. Heap). This also depicts about the GC visualization tools and CLR 4.0 GC – Back Ground garbage collector.

Statistics

Views

Total Views
1,399
Views on SlideShare
1,394
Embed Views
5

Actions

Likes
0
Downloads
56
Comments
0

2 Embeds 5

http://www.slideshare.net 4
http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Garbage Collection In  Micorosoft Garbage Collection In Micorosoft Presentation Transcript

    • Garbage Collection in Microsoft .NET Smitha Natarajamurthy
      • In and out of Garbage Collector..
      • GC in .NET Framework
      • How GC works? And Garbage Collector Algorithms
        • Mark – Sweep GC
        • Generational GC
      • Finalization vs. Dispose
      • Some tips on being friendly to GC
      • Garbage Collection Visualizations
        • CLR Profiler
        • Process Explorer
      • So, what’s new in the CLR 4.0 GC? - "Background" Garbage Collector.
      Take Away
    • GC in .NET Framework
    • Stack vs. Heap The Stack is more or less responsible for keeping track of what's executing in our code (or what's been "called").  The Heap is more or less responsible for keeping track of our objects (our data, well... most of it - we'll get to that later.).
      • Here are our two golden rules:
        • Reference Type always goes on the Heap.
        • Value Types and Pointers always go where they were declared. 
      How it is decided what goes where? (Huh?)           public class MyInt           {                       public int MyValue;           } And the following method is executing:           public MyInt AddFive( int pValue)           {                 MyInt result = new MyInt();                 result.MyValue = pValue + 5;                 return result;           }
    • Terminology How the objects are laid out in the manage heap.
    • When/how the GC runs
      • System is low in memory
      • Memory is too much fragmented
      • After quanta of allocation
      • There are multiple types of Garbage Collector available:
      • Mark-Sweep GC
      • Generational GC
      • Copying GC
      • Reference Counting GC
    • Mark – Sweep GC
    • GC – Save Point
    • Mark – Sweep in Action
    • Compaction
    • Generational GC
    •  
    • Finalization vs. Dispose
      • public class MyClass : IDisposable
      • {
        • public MyClass ()
        • {
        • }
        • public virtual void Dispose()
        • {
        • Dispose(true);
        • GC.SuppressFinalize(this);
        • }
        • protected virtual void Dispose(bool disposing)
        • {
        • if(!disposed)
        • {
        • if (disposing = true)
        • {
        • //Cleanup managed resources
        • }
        • //Cleanup unmanaged resources
        • }
        • disposed = true;
        • }
        • ~ MyClass ()
        • {
        • Dispose(false);
        • }
      • }
    • Some tips on being friendly to GC
      • Avoid object pools
      • Do Not Use GC.Collect()
      • Be careful about un-intended object creation
      • Finalization
      • Be careful around large objects (>85000B):
      • Pinning is bad for GC Performance
      • Set reference to null as soon you can specially before blocking
      • Weak References
    • Garbage Collection Visualizations - CLR Profiler - Process Explorer
    • So, what’s new in the CLR 4.0 GC? "Background" Garbage Collector .NET 4.0 introduces Background GC . The Concurrent GC allocates memory while running but in the current segment which is 16 MB on a workstation. After that all threads are suspended. The Background GC allows a separate ephemeral GC - gen0 and gen1 - to be started while the full GC - gen0, 1, and 2 - is running and that means access to another memory segment. CLR 4.0 changes that to support background collection, which can do a Generation 0 and Generation 1 collection at the same time as a Generation 2 collection. This means that now only unusual circumstances should lead to long latency times.
    • Thank You!