String.Empty versus "" – The real deal

This is one topic that keeps popping up every now and then. A lot of people seem to be curious about the performance implications of using one versus the other, and not unexpectedly, a lot of different answers come up. To settle it once for all, here’s a small program that uses both of them. namespace ConsoleApplication{ class Program { static void Main() { Method1(); Method2(); Console.ReadLine(); Method1(); Method2(); } [MethodImpl(MethodImplOptions.NoInlining)] static void Method1() { string s = “”; DoNothing(s); } [MethodImpl(MethodImplOptions.NoInlining)] static void Method2() { string s = string.Empty; DoNothing(s); } [MethodImpl(MethodImplOptions.NoInlining)] static void DoNothing(string s) { Console.WriteLine(s); } … Continue reading String.Empty versus "" – The real deal

The case of the leaking thread handles

This was one of the more challenging and interesting problems to debug in a while. When testing out code for an unrelated fix, I noticed that the application’s handle count, as seen in the Handles column in Task Manager, kept rising steadily. WinDbg, showed that the app was leaking thread handles. 0:003> !handle1417 HandlesType               CountEvent              452Section            8File               12Port               2Directory          3Thread             916Desktop            1KeyedEvent         1 Half expecting the code to hold references to dead threads, I dumped Thread objects in the GC heap. 0:003> !dumpheap -stat -type System.Threading.Threadtotal 353 objectsStatistics:      MT    Count    TotalSize … Continue reading The case of the leaking thread handles