From: Robert Klemme Date: 2006-07-07T00:45:03+09:00 Subject: Re: [BUG] thread/sync.rb memory corruption 2006/7/6, ara.t.howard@noaa.gov : > On Thu, 6 Jul 2006, Robert Klemme wrote: > > > Ara, I still believe the error is in the script (see my other posting). > > > > Kind regards > > > > robert > > hi robert- > > i never saw any post!? maybe mailing issues again? sigh... > > can you re-state? No prob. I'll put you on CC - just in case. robert 2006/7/6, ara.t.howard@noaa.gov : > 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. Yes, but they are still queued up against the mutex. I completely agree with Tom's analysis. Having an Observer trigger the notification again is definitively a bad idea - at least if events are not queued up. Kind regards robert -- Have a look: http://www.flickr.com/photos/fussel-foto/