GC$B$NLdBj(B


#1

ã‘ã„ã˜ã‚…ï¼ ã„ã—ã¤ã‹ã§ã™.

添付のプログラムを実行すると. ほとんどのオブジェクト(文字列)がGCで回収
されないまま残ってしまいます.

これって, ruby側でもっと効率よくGCするようにするってことは不可能でしょ
うか?

ちなみに, コメントをはずすとゴミが回収されます.

いろんなパターンのスクリプトも添付します. Queueを使っていても同じ問題
が起こります. 1.9系だとほぼ確実に再現しますし, 1.8ç³»ã ã¨å†ç¾ã™ã‚‹å ´åˆã‚‚
あるってかんじになっています.


def foo(times)
exp = []

times.times do
  exp.push rand.to_s
end
exp.push nil
exp

end

def bar(exp)
while e = exp.shift
e
end
p exp
end

exp = foo(1000000)
bar(exp)
#exp = foo(100)
#bar(exp)

GC.start
count = 0
ObjectSpace.each_object(String){|s| count += 1}
puts count


#2

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:38448] GCe$B$NLdBje(B”
on Thu, 14 May 2009 18:17:12 +0900, removed_email_address@domain.invalid (Keiju
ISHITSUKA) writes:

|e$BE:IU$N%W%m%0%i%`$r<B9T$9$k$He(B. e$B$[$H$s$I$N%*%V%8%’%/%He(B(e$BJ8;zNse(B)e$B$,e(BGCe$B$G2s<}e(B
|e$B$5$l$J$$$^$^;D$C$F$7$^$$$^$9e(B.
|
|e$B$3$l$C$Fe(B, rubye$BB&$G$b$C$H8zN($h$/e(BGCe$B$9$k$h$&$K$9$k$C$F$3$H$OIT2DG=$G$7$ge(B
|e$B$&$+e(B?

e$B$U$`!#e(B

% ruby -v /tmp/gc.rb
ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
[]
1000160

e$B$?$7$+$K2s<}$5$l$F$J$$$+$b$7$l$^$;$s$M!#$G$b!"e(B1.9e$B$G$O$A$g$Ce(B
e$B$H;v>p$,0c$&$h$&$G$9!#e(BMBARIe$B%Q%C%A$r<h$j9~$s$@$s$G$7$?$C$1e(B >
e$B$J$+$@$5$se(B

% ruby1.9 -v /t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$Ge(B
e$B$9$,e(B?

__
---------------------------------------------------->> e$B@PDMe(B
e$B7=<ye(B <<—
---------------------------------->> e-mail: removed_email_address@domain.invalid <<—