Your SlideShare is downloading. ×
Introduction of c# day2
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Introduction of c# day2

138
views

Published on

Read it

Read it

Published in: Education

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
138
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 2 Microsoft .NET Framework Overview Presented By Arun Kumar Singh & Team Master of Computer Application Microsoft® Certified Professional MCP id- 7802107www.aumcp2013.jimdo.com arunsingh026@hotmail.com All Right Reserved@ AUMCP group of annamalai university(Arun Singh)
  • 2. Garbage Collection(Memory Allocate & Reallocate) Garbage Collection in .NET framework The Garbage collection is very important technique in the .NET framework to free the unused objects in the memory and free the space for next incoming process. The garbage collection (GC) is new feature in Microsoft .NET framework. When we have a class that represents an object in the runtime that allocates a memory space in the heap memory. All the behavior of that objects can be done in the allotted memory in the heap. Once the activities related to that object is get finished then it will be there as unused space in the memory. All Right Reserved@ aumcp group of annamalai university(Arun Singh)
  • 3. The earlier releases of Microsoft products have used amethod like once the process of that object get finished thenit will be cleared from the memory.Microsoft was planning to introduce a method that shouldautomate the cleaning of unused memory space in the heapafter the life time of that object. Eventually they haveintroduced a new technique "Garbage collection". It is very important part in the .NET framework. Now ithandles this object clear in the memory implicitly. Itovercomes the existing explicit unused memory spaceclearance. All Right Reserved@ aumcp group of annamalai university(Arun Singh)
  • 4. Garbage Collection Works?The heap memory is divided into number of generations.Normally it is three generations. The Generation 0 is for shortlive objects, Generation 1 is for medium live objects whichare moved from Generation 0. Generation 2 is for long liveobjects.When an object is created then it will allocate the memoryspace which will be higher. It will be in the Generation 0 andthe memory allocation will be continuous without any spacebetween the generations of garbage collectors. All Right Reserved@ aumcp group of annamalai university(Arun Singh)
  • 5. Managed Heap Generation 0Generation 1 Generation 2 All Right Reserved@ aumcp group of annamalai university(Arun Singh)
  • 6. How it’sWork? Garbage Collection should be handled by the .NET framework. Implicit When object is created then it will be placed in the Generation 0. The garbage collection uses an algorithm which checks the objects in the generation, according to there generation CLR decided when it will be removed from the memory. The two kinds of objects. One is Live Objects and Dead Objects. The Garbage collection algorithm collects all unused objects that are dead objects in the generation. If the live objects running for long time then based on that life time it will be moved to next generation. The object cleaning in the generation will not take place exactly after the life time over of the particular objects. It takes own time to implement the sweeping algorithm to free the spaces to the process. All Right Reserved@ aumcp group of annamalai university(Arun Singh)
  • 7. When it happens The garbage collector periodically checks the heap memory to reclaim the objects when the object has no valid references in the memory. When an object is created then it checks the available space in the heap for that object if it is available then it will allocate the memory, if the available space is not available to allot the space then it automatically garbage collector collect the unused objects. If all object are valid referenced then it gets additional space from the processor. All Right Reserved@ aumcp group of annamalai university(Arun Singh)
  • 8. Example code to know more about Garbage Collection MaxGeneration This property in the GC class returns the total number of generations.using System; The GC is class in whichclass GCExample1 the MaxGeneartion ,which{ are count the no of public static void Main(string[] args) generation { try { Console.WriteLine("GC MaximumGenerations:" + GC.MaxGeneration); } catch (Exception oEx) { Console.WriteLine("Error:" + oEx.Message); } All Right Reserved@ aumcp group of annamalai } university(Arun Singh)
  • 9. GetTotalMemory and GetGenerationusing System;class BaseGC{ public void Display() { Console.WriteLine("Example Method"); } GettotalMemory is} the method,which are gives a totalclass GCExample2{ public static void Main(string[] args) { try { Console.WriteLine("Total Memory:" + GC.GetTotalMemory(false)); BaseGC oBaseGC = new BaseGC(); Console.WriteLine("BaseGC Generation is :" + GC.GetGeneration(oBaseGC)); Console.WriteLine("Total Memory:" + GC.GetTotalMemory(false)); } All Right Reserved@ aumcp group of annamalai university(Arun Singh)
  • 10. catch (Exception oEx) { Console.WriteLine("Error:" + oEx.Message); } }}Result Here GetTotalMemory shows the total number of memory occupied by the various resources. Here I have added one more managed code objects in the heap memory. After adding, the size of the memory has increased. The GetGeneration method will find out the particular managed object in the which generation. Here it shows the Object oBaseGC in the 0th generation. All Right Reserved@ aumcp group of annamalai university(Arun Singh)
  • 11. CollectionCount and Collect using System; class Cal { public int Add(int a, int b) { return (a + b); } public int Sub(int a, int b) { return (a - b); } public int Multi(int a, int b) { return (a * b); } public int Divide(int a, int b) { return (a / b); } All Right Reserved@ aumcp group of annamalai university(Arun } Singh)
  • 12. class GCExample3{ public static void Main(string[] args) { Cal oCalci = new Cal(); Console.WriteLine("Calci object is now on " + GC.GetGeneration(oCalci) + "Generation"); Console.WriteLine("Garbage Collection Occured in 0thGeneration:" +GC.CollectionCount(0)); Console.WriteLine("Garbage Collection Occured in 1thGeneration:" +GC.CollectionCount(1)); Console.WriteLine("Garbage Collection Occured in 2thGeneration:" +GC.CollectionCount(2)); GC.Collect(0); Console.WriteLine("Garbage Collection Occured in 0thGeneration:" +GC.CollectionCount(0)); }} All Right Reserved@ aumcp group of annamalai university(Arun Singh)
  • 13. Result The CollectionCount helps us to find out the generation wise garbage collection occurred. As we know there are totally three generations in the garbage collector. Here I have passed argument as one for know the first generation. Initially it was 0. Then through the code I have collected the unused objects in the 0th generation. Again I have checked the CollectionCount in the 0thgeneration. Now it says 1. The Collect method used to collect the unreferenced objects in the heap memory. It will clear the object and reclaim the memory space. All Right Reserved@ aumcp group of annamalai university(Arun Singh)
  • 14. Common Type System(CTS)As .NET Framework is language independent and support over 56different programming languages, many programmers will write data typesin their own programming language.For example, an integer variable in C# is written as int, whereas in VisualBasic it is written as integer. Therefore in .NET Framework you have singleclass called System.Int32 to interpret these variables. Similarly, for theArrayList data type .NET Framework has a common type calledSystem.Collections.ArrayList.This system is called Common Type System. The types in .NETFramework are the base on which .NET applications, components, andcontrols are built. Common Type System in .NET Framework defines howdata types are going to be declared and managed in runtime. All Right Reserved@ AUMCP group of annamalai university(Arun Singh)
  • 15. There are two general types of categories in .NETFramework that Common Type System support.Value Types . Value types directly a contain data and are user-defined or built-in. they are placed in a stack or in order in astructure. E.g int a=8; //directly createdReference Types. Reference types store a reference of thevalue’s memory address. They are allocated in a heapstructure.E.g as obj=new as(); //object created All Right Reserved@ aumcp group of annamalai university(Arun Singh)
  • 16. Tomorrow Conti………………..16 All Right Reserved@ aumcp group of annamalai 3/22/2013 university
  • 17. Q & A SessionMore Information Post Your Questionson www.aumcp2013.jimdo.co m aumcp2013@live.com All Right Reserved@ aumcp group of annamalai university(Arun Singh)
  • 18. Thanks to AllAll Right Reserved@ aumcp group of annamalaiuniversity(Arun Singh)