in reply to Multialarm loop

What kind of system are you on, Excalibor? If it's a *NIX box, using a daemon that runs your checking loops is the way to go. Since each is a multiple of its smaller brethren, you have the daemon wake up once every 25 seconds (~) to perform phase_1 cleanup. After doing that, it checks a pair of countdown counters to see if 10 cycles of phase_1 have passed and it's time for a phase_2 sweep, and if 100 phase_1 cycles (or ten sets of phase_2) have passed and it's time for a phase_3 sweep. The daemon will remain resident, so you don't need persistent storage for the counter variables; just check them when you wake up.

It's a mistake to try to use many timers in a situation like this. Far better to use one timer and a couple of counters to accomplish the goal.

The one caution I'd give is that the time required to actually do the GC is a variable amount, depending on how many things need to be GCed. It might be appropriate to have the phase_2 and phase_3 cleanups launched as separate processes from the daemon, and use renice to adjust their system resource priority. In any event, you want to have the daemon waking up more often than you need it to to make sure that you do not overrun your interval.