using System; namespace GCCollectIntExample { class MyGCCollectClass { private const long maxGarbage = 1000; static void Main() { MyGCCollectClass myGCCol = new MyGCCollectClass(); // Determine the maximum number of generations the system // garbage collector currently supports. Console.WriteLine("The highest generation is {0}", GC.MaxGeneration); myGCCol.MakeSomeGarbage(); // Determine which generation myGCCol object is stored in. Console.WriteLine("Generation: {0}", GC.GetGeneration(myGCCol)); // Determine the best available approximation of the number // of bytes currently allocated in managed memory. Console.WriteLine("Total Memory: {0}", GC.GetTotalMemory(false)); // Perform a collection of generation 0 only. GC.Collect(0); // Determine which generation myGCCol object is stored in. Console.WriteLine("Generation: {0}", GC.GetGeneration(myGCCol)); Console.WriteLine("Total Memory: {0}", GC.GetTotalMemory(false)); // Perform a collection of all generations up to and including 2. GC.Collect(2); // Determine which generation myGCCol object is stored in. Console.WriteLine("Generation: {0}", GC.GetGeneration(myGCCol)); Console.WriteLine("Total Memory: {0}", GC.GetTotalMemory(false)); Console.Read(); } void MakeSomeGarbage() { Version vt; for(int i = 0; i < maxGarbage; i++) { // Create objects and release them to fill up memory // with unused objects. vt = new Version(); } } } }
Be Different with excellent knowledge A Devloper Blog....
Tuesday, June 11, 2013
How Garbage Collector works
Subscribe to:
Post Comments (Atom)
AngularJS Basics - Part 1
AngularJS What is AngularJS · Framework by googl...
-
Make Your Own Notepad In this tutorial we will be making a simple C# Notepad with the option to Clear, Cut, Copy, Paste, Select All, Save...
-
What is View? A simple view can be thought of as a subset of a table. It can be used for retrieving data, as well as updating or deleting r...
No comments:
Post a Comment
Your comment is pending for approval