简体   繁体   中英

Very simple Ruby GServer leaking memory

I've got the following Ruby script:

class Server < GServer

  def initialize    
    super(10001)
  end


  def serve(io)
    while true
     io.puts `ps -o rss= -p #{$$}`.to_i
    end
  end

end

server = Server.new
server.start

while true
  sleep 10
end

When I open a connection to the server, it shows increasing memory usage over time, without me opening any new connections or doing anything at all.

Am I doing something wrong, or is there a memory leak issue in GServer?

BTW: I tested it on MacOSX with Ruby 1.8.7 and on a Debian System with 1.9.2.

16kb doesn't necessarily mean a memory leak. If you have a real memory leak it will go up and up to hundreds of MB's over time. That being said you can look for memory leaks using mem-prof and valgrind.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM