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

Where Am I

That’s my first Windows mobile application you’re seeing below. Most cellular service providers in India broadcast the location of the communicating cell tower to the phone. Where Am I (Wami) is a managed Windows Mobile application that uses the broadcast information to let you know where you are and when you will reach your destination. The screenshot above shows that I’m at INDIRA NAGAR, somewhere close to TIDEL PARK and that I’ll reach home at 12:59 AM. How does Wami do this? There’s a sister application, RouteLogger, that automatically logs cell tower locations (INDIRA NAGAR, for e.g) along with the … Continue reading Where Am I

Itertools for C# – Tee

Tee is a cool function that “clones” enumerators whatever their current state is – it basically allows you to branch off an enumerator into as many enumerators as you want, all independent of each other.  You can do something like List<int> list = new List<int> { 1, 2, 3, 4, 5 };IEnumerator<int> iterable1 = list.GetEnumerator();IEnumerator<int> []teedIterables = Itertools.Tee(iterable1, 2);foreach(int val in teedIterables[0]){ Console.WriteLine(val);}foreach(int val in teedIterables[1]){ Console.WriteLine(val);}// prints 1 2 3 4 5 1 2 3 4 5 If there was a iterable1.MoveNext() before the call to Tee, then the output would have been 2 3 4 5 2 3 … Continue reading Itertools for C# – Tee