// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Diagnostics; namespace E { class MainClass { public static void NonRecursive(string s, int n) { int m = 0; for(int i = 0; i < n; i++) { if (s.Trim().ToLower().EndsWith(".jpg")) { m++; } } Console.WriteLine(m); Console.WriteLine("after: " + GC.GetTotalMemory(false)); GC.Collect(); Console.WriteLine("GC: " + GC.GetTotalMemory(false)); } public static void Recursive(string s, int n) { if(n > 0) { Recursive(s, n - 1); } else { Console.WriteLine("after: " + GC.GetTotalMemory(false)); GC.Collect(); Console.WriteLine("GC: " + GC.GetTotalMemory(false)); } } public static void Test(string s) { Console.WriteLine("before: " + GC.GetTotalMemory(false)); NonRecursive(s, 1000000); Recursive(s, 10000); } public static void Main(string[] args) { Test("xxx.jpg"); Test("xxx.gif"); } } }