From: ara.t.howard@... Date: 2006-07-06T07:39:00+09:00 Subject: Re: thread mystery On Thu, 6 Jul 2006, Tom Rauchenwald wrote: > ara.t.howard@noaa.gov writes: > >> any idea why this script slows downs drastically as it runs and seems to leak >> memory? > > First, I'm not a Ruby expert or something, but.. > > [Code skipped] > >> switch = Switch.new > > Here you create the switch. > >> toggle = SwitchToggle.new switch > > Here, toggle is created and registered as listener (in the constructor) > >> switch.on! > > So now you switch it on. > Toggle gets notified, and creates a thread that switches it off. > But when that Thread switches it off, toggle gets notified, and starts a > thread that switches it on again.. > Basically it's an infinite loop, and i suspect it's leaking because GC > doesn't kick in. it would be, but the synchronize prevents two threads from entering any of the Switch methods at a time so only thread can actually be running at once. -a -- suffering increases your inner strength. also, the wishing for suffering makes the suffering disappear. - h.h. the 14th dali lama