From: Joe Van Dyk Date: 2005-04-27T11:45:44+09:00 Subject: Re: memory leak eek. copy/paste borked. See below for correct version. On 4/26/05, Joe Van Dyk wrote: > Got a memory leak in the following code.. not sure if DRb is necessary > in it or not. > > Put the code into a file named test.rb, btw. > > I think I tracked it down to the SystemVIPC::MessageQueue#recv method. > If I don't give it a high receive length (like 8192), I don't see the > leak. If I do give it a high length, the program takes up a very > large amount of space pretty quickly... about an increase of a meg > every five seconds. > > Any ideas? (On my linux system, kernel.msgmax is set to 10000 if it matters) > # test.rb require 'drb' require 'sysvipc' class Foo def initialize @key = SystemVIPC::ftok("test.rb", 1) @msg = SystemVIPC::MessageQueue.new(@key, 0777 | SystemVIPC::IPC_CREAT) end def recv continue = true while continue begin @msg.recv(1, 8192, SystemVIPC::IPC_NOWAIT) rescue continue = false end end end def send @msg.send(1, "HELLO WORLD HELLO WORLD") end end f = Foo.new some_thread = Thread.new(f) do |foo| loop do foo.recv sleep 1 end end some_thread = Thread.new(f) do |foo| loop do foo.send sleep 1 end end DRb.start_service('druby://localhost:8000', f) DRb.thread.join