From: YuDerek Date: 2008-04-13T00:09:27+09:00 Subject: Re: WeakRef -- excessive memory usage? --_063e85db-4518-4a37-b370-5c57d2441fa2_ Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: 8bit puts 'weakref'r = require 'weakref'puts rs = 'hello'a = []GC.disable #<--------5.times { gets puts "100times" 100.times { WeakRef.new(s) } puts "end times" } In fact, GC works. GC is enabled by default, You may not need to use GC.start to start GC, it seems that ruby deals with GC well. Without GC.disable, the memory usage is about 10,500K every iteration. But when you disable GC, the memory usage is as below: before 5,200k after 1 77,764k2 145,976k 3 231,088k 4 277,376k I think ruby actually get these space back, but it keeps these space somewhere, so it will be fast next time you make some new things without getting it from OS. > Date: Sat, 12 Apr 2008 23:05:05 +0900> From: "david mail"@ruby-lang.org> Subject: WeakRef -- excessive memory usage?> To: ruby-talk@ruby-lang.org> > Hi everyone, I recently had a problem with memory usage in my ruby 1.8.6 > program. It had ballooned from about 65mb after startup to 300mb. I > tracked the problem down to my usage of WeakRefs. Storing object_ids > instead got the memory usage back to where it was.> > In the following example I'm checking memory usage with Windows Task > Manager.> > > > irb> > irb(main):001:0> require 'weakref'> => true> irb(main):002:0> s = 'hello'> => "hello"> irb(main):003:0> a = []> => []> > (memory usage is 4,171k at this point)> > irb(main):004:0> 100.times { a << WeakRef.new(s) }> => 100> > (memory usage is now 54,380k)> > > Repeated calls to GC.start doesn't reduce the memory usage at this > point. Am I missing something?> > David> _________________________________________________________________ ������MSN�������������������������������������� http://mobile.msn.com.cn/ --_063e85db-4518-4a37-b370-5c57d2441fa2_--