I've noticed Emacs doing a lot of garbage collection after I'velost a remote network connection where I had an Emacs window displayed. (This is Emacs 24.3.91 with the changes from Dmitry; without the changes the lost connection would kill Emacs altogether.) Typically it seems to be GCing a few times in the span of a couple seconds or so, mostly after I've typed something. Each character seems to be enough to trigger it, so if I start typing a line of text, the "Garbage collecting..." messages are constantly flickering in the minibuffer.
I eventually traced it back to lots of invocations of timercallbacks; while I'm still tracing down exactly why they're happening so much, I noticed that the CPU utilization of Emacs is hovering around 100% now. (It's sluggish but does still respond.) According to strace it seems to be constantly doing this, over and over:
In thisprocess, fd 20 is the dropped TCP connection for the remote display, and fd 7 is the unix-domain socket to the local display. Since the remote connection is closed, pselect6 returns immediately, but we never drop it from the fd set.
I'm still trying to figure out if it's incorrectly firing an idle timer handler each time around a loop or somethinglike that, which might account for the excessive garbage collection.
My testmethod:
1) Start (modified) Emacs on :0 in daemon mode via emacsclient -c -a "" -n
2) Use ssh to log into the desktop again with adifferent $DISPLAY
3) Use emacsclient to get an X11 windowpopped up
4) Use "~." to kill thessh session
5) Use top, strace, etc to look at the spinningEmacs process