Project

General

Profile

Actions

Bug #11332

closed

Arrayの操作でcrubyインタプリタのメモリリークが起きる

Added by metanest (Makoto Kishimoto) over 8 years ago. Updated over 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-dev:49166]

Description

きしもとです

Arraysort! と、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

Related issues 2 (0 open2 closed)

Has duplicate Ruby master - Bug #11333: Arrayの操作でcrubyインタプリタのメモリリークが起きるClosedActions
Has duplicate Ruby master - Bug #11334: Arrayの操作でcrubyインタプリタのメモリリークが起きるClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0