Example #1
0
        static void Main(string[] args)
        {
            if (CLRProfilerControl.ProcessIsUnderProfiler)
            {
                Console.WriteLine("Process is running under CLRProfiler");
            }
            else
            {
                Console.WriteLine("Process is not running under CLRProfiler - exiting");
                return;
            }

            string.Format("");

            // Make sure we get rid of everything we can get rid of
            GC.Collect();
            GC.WaitForPendingFinalizers();

            // This will trigger another garbage collection and dump what's still live
            // This is our "before" snapshot.
            CLRProfilerControl.DumpHeap();

            ht = new Hashtable();
            for (int i = 0; i < 1000; i++)
            {
                ht[i] = string.Format("Value {0}", i);
            }

            // The memory is retained because ht is a static - enable the following statement
            // to make sure the garbage collector can clean up
            //ht = null;

            // Make sure we get rid of everything we can get rid of
            GC.Collect();
            GC.WaitForPendingFinalizers();

            // This will trigger another garbage collection and dump what's still live
            // This is our "after" snapshot.
            CLRProfilerControl.DumpHeap();

            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
        }
Example #2
0
        static void Main(string[] args)
        {
            // Set our "before" marker in the log file
            CLRProfilerControl.LogWriteLine("Before loop - time = {0} milliseconds", DateTime.Now.Millisecond);

            ht = new Hashtable();
            for (int i = 0; i < 1000; i++)
            {
                ht[i] = string.Format("Value {0}", i);
            }

            // Set our "after" marker in the log file
            CLRProfilerControl.LogWriteLine("After loop - time = {0} milliseconds", DateTime.Now.Millisecond);

            // Do some more to make things more interesting...
            for (int i = 0; i < 1000; i++)
            {
                ht[i] = string.Format("Value {0}", i);
            }

            // Set another "after" marker in the log file
            CLRProfilerControl.LogWriteLine("After second loop - time = {0} milliseconds", DateTime.Now.Millisecond);

            // The memory is retained because ht is a static - enable the following statement
            // to make sure the garbage collector can clean up
            // ht = null;

            // Make sure we get rid of everything we can get rid of
            GC.Collect();
            GC.WaitForPendingFinalizers();

            // This will trigger another garbage collection and dump what's still live
            // This is our "after" snapshot.
            CLRProfilerControl.DumpHeap();

            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
        }