[ruby-dev:49175] [Ruby trunk - Bug #11332] Arrayの操作でcrubyインタプリタのメモリリークが起きる

From: ksmakoto@...4u.or.jp
Date: 2015-07-05 03:03:34 UTC
List: ruby-dev #49175
Issue #11332 has been updated by Makoto Kishimoto.


rev.51148 で実行して直っていることを確認しました

----------------------------------------
Bug #11332: Arrayの操作でcrubyインタプリタのメモリリークが起きる
https://bugs.ruby-lang.org/issues/11332#change-53289

* 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 で調べるとオブジェクトは増えたり
\# 大きくなったりはしていません。

~~~ruby
# -*- 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/

In This Thread

Prev Next