From: Eric Hodel Date: 2006-07-06T07:37:09+09:00 Subject: Re: thread mystery On Jul 5, 2006, at 3:31 PM, 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. No, the number of live threads (Thread.list) remains stable. Watching ObjectSpace shows the GC operating, but the number of thread instances never decreases. -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com