Demonstrates forced garbage collection : Garbage Collection « Development Class « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Class Interface
3. Collections Data Structure
4. Components
5. Data Types
6. Database ADO.net
7. Design Patterns
8. Development Class
9. Event
10. File Stream
11. Generics
12. GUI Windows Form
13. Language Basics
14. LINQ
15. Network
16. Office
17. Reflection
18. Regular Expressions
19. Security
20. Services Event
21. Thread
22. Web Services
23. Windows
24. XML
25. XML LINQ
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / C Sharp » Development Class » Garbage CollectionScreenshots 
Demonstrates forced garbage collection
Demonstrates forced garbage collection

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/
//
// gc.cs -- Demonstrates forced garbage collection
//
//          Compile this program with the following command line:
//              C:>csc gc.cs
//
namespace nsGarbage
{
    using System;
    using System.Threading;
    
    public class GCDemo
    {
        static public void Main ()
        {
            long Mem = GC.GetTotalMemory (false);
            Console.WriteLine ("Beginning allocated memory is " + Mem);
            for (int x = 0; x < 10000; ++x)
            {
                clsClass howdy = new clsClass();
            }
            Mem = GC.GetTotalMemory (false);
            Console.WriteLine ("Allocated memory before garbage collection is " + Mem);
            GC.Collect ();
            Mem = GC.GetTotalMemory (true);
            Console.WriteLine ("Allocated memory after garbage collection is " + Mem);
        }
    }
    class clsClass
    {
        public clsClass () { }
        public int x = 42;
        public float f = 2E10f;
        public double d = 3.14159;
        public string str = "This here's a string";
    }
}


           
       
Related examples in the same category
1. If object array is still alive
2. Check the Generation for an object array
3. Estimated bytes on heap
4. MaxGeneration is zero based.
5. Get Total Memory
6. demonstrates forced garbage collection 1demonstrates forced garbage collection 1
7. System.IDisposable interface and ensure fastest cleaning up as possible after an objectSystem.IDisposable interface and ensure fastest cleaning up as possible after an object
8. IDisposable interface
9. Print out how many times a generation has been swept.
10. Finalizable Disposable Class with using
w__w_w___.j__a__v___a___2_s__._c_o__m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.