@@ -121,6 +121,11 @@ registerKillThread m = do
121121 wtid <- myThreadId >>= mkWeakThreadId
122122 register m $ killIfExist wtid
123123
124+-- If ThreadId is hold referred by a strong reference,
125+-- it leaks even after the thread is killed.
126+-- So, let's use a weak reference so that CG can throw ThreadId away.
127+-- deRefWeak checks if ThreadId referenced by the weak reference
128+-- exists. If exists, it means that the thread is alive.
124129killIfExist :: Weak ThreadId -> TimeoutAction
125130killIfExist wtid = deRefWeak wtid >>= maybe (return ()) killThread
126131