From: s.wanabe@... Date: 2015-07-04T14:54:21+00:00 Subject: [ruby-dev:49169] [Ruby trunk - Bug #11333] [Closed] Arrayの操作でcrubyインタプリタのメモリリークが起きる Issue #11333 has been updated by _ wanabe. Status changed from Open to Closed 「メールをチケットにする」操作のミスで重複チケットを作ってしまったので閉じます。 失礼いたしました。 ---------------------------------------- Bug #11333: Arrayの操作でcrubyインタプリタのメモリリークが起きる https://bugs.ruby-lang.org/issues/11333#change-53280 * Author: Makoto Kishimoto * Status: Closed * Priority: Normal * Assignee: * ruby -v: * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- きしもとです Array の sort! と、pop または shift の操作を組み合わせると、わずか ですが ruby インタプリタのメモリリークを引き起こすようです。多数回 繰返すと、どんどん大きくなります。 以下のサンプルを手元の環境(FreeBSD/amd64のruby 2.1.6、ruby 2.2.2、 trunk (r51120) )で試すと、どれもインタプリタのプロセスのメモリ サイズが大きくなっていきます(最後はメモリを確保できなくなって 落ちる)。 # ObjectSpace.memsize_of_all で調べるとオブジェクトは増えたり # 大きくなったりはしていません。 # -*- mode:ruby ; coding:utf-8 -*- def sample rg arr = [] sz = 5 + rg.rand(5) i = 0 while i < sz do arr[i] = rg.rand i += 1 end until arr.empty? do arr.sort! arr.pop #arr.shift end end randgen = Random.new 12345 count = 0 while true do sample randgen if (count += 1) > 1000000 then count = 0 p "GC" GC.start end end -- https://bugs.ruby-lang.org/