Timer, event and garbage collection : am I missing something?

OK, I think I know what’s going on… I looked at the code of the Timer class with Reflector, and I found the following instruction in the setter of the Enabled property :

this.timerRoot = GCHandle.Alloc(this);

So, when it is started, the timer allocates a GCHandle for itself, which prevents its collection by the GC…

Leave a Comment