[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Garbage collection/memory unfreed problem

Mark Noworolski

11/3/2006 5:56:00 AM

It appears that the ruby garbage collector is not freeing up unused
memory on my linux machine, but IS on my windows machine... I'm baffled
and troubled. Any advice would be appreciated...

Using the attached test script, in linux I observe the VMRSS start at
around 1.5Meg, then go up to ~20Meg by iteration 3 or 4, and sit there
for the remaining iterations. Then once the t array goes out of scope, I
see it drop by a few meg. The GC.start only drops apparent memory
consumption to ~14Meg.

Meanwhile, on windows XP, I see it increase to around 20Meg, then sit
around there until the GC.free, which brings it back down to around
5Meg, close to the starting point.

Can anybody explain the difference here? Is the 14meg _really_
unavailable to the OS in linux?

-------------
class Grab
def initialize
@myhash={}
0.upto(100000) {|i| @myhash[i]="#{i} Im a part of a hash"}
end
end

def memuse
#IO.read("/proc/#{Process.pid}/status") =~ /VmSize.* (\d+) k/
"Hi"
end

puts "Mem before anything: #{memuse}"
sleep 10;
0.upto(10) do |x|
t||=Array.new
t[x]=Grab.new
puts "Mem in scope #{x}: #{memuse}"
sleep 1;
end
puts "mem out of scope #{memuse}"
sleep 10;
GC.start
puts "Mem after GC: #{memuse}"
sleep 10;

3 Answers

Lei Ming

11/3/2006 9:25:00 AM

0

Hi Mark,

I tried your code on a RHEL4 x86-64 server and I got the same problem
(the RSS size was even bigger). I also tried repeating your main loop
for several times, and the RSS size (after GC) increased each time. So
I think this is inefficiency in Ruby's GC implementation.

Since it's RSS, physical pages have been allocated for the Ruby
process's data section, I don't think Linux can use this part of memory
for other purpose, unless the Ruby process is killed by the OOM killer
:-(

I don't know the reason for this problem but I'll try to find out.

Lei Ming

Mark Noworolski wrote:
> It appears that the ruby garbage collector is not freeing up unused
> memory on my linux machine, but IS on my windows machine... I'm baffled
> and troubled. Any advice would be appreciated...
>
> Using the attached test script, in linux I observe the VMRSS start at
> around 1.5Meg, then go up to ~20Meg by iteration 3 or 4, and sit there
> for the remaining iterations. Then once the t array goes out of scope, I
> see it drop by a few meg. The GC.start only drops apparent memory
> consumption to ~14Meg.
>
> Meanwhile, on windows XP, I see it increase to around 20Meg, then sit
> around there until the GC.free, which brings it back down to around
> 5Meg, close to the starting point.
>
> Can anybody explain the difference here? Is the 14meg _really_
> unavailable to the OS in linux?
>
> -------------
> class Grab
> def initialize
> @myhash={}
> 0.upto(100000) {|i| @myhash[i]="#{i} Im a part of a hash"}
> end
> end
>
> def memuse
> #IO.read("/proc/#{Process.pid}/status") =~ /VmSize.* (\d+) k/
> "Hi"
> end
>
> puts "Mem before anything: #{memuse}"
> sleep 10;
> 0.upto(10) do |x|
> t||=Array.new
> t[x]=Grab.new
> puts "Mem in scope #{x}: #{memuse}"
> sleep 1;
> end
> puts "mem out of scope #{memuse}"
> sleep 10;
> GC.start
> puts "Mem after GC: #{memuse}"
> sleep 10;

Eric Hodel

11/5/2006 10:44:00 PM

0

On Nov 2, 2006, at 9:55 PM, Mark Noworolski wrote:

> It appears that the ruby garbage collector is not freeing up unused
> memory on my linux machine, but IS on my windows machine... I'm
> baffled
> and troubled. Any advice would be appreciated...
>
> Using the attached test script, in linux I observe the VMRSS start at
> around 1.5Meg, then go up to ~20Meg by iteration 3 or 4, and sit there
> for the remaining iterations. Then once the t array goes out of
> scope, I
> see it drop by a few meg. The GC.start only drops apparent memory
> consumption to ~14Meg.
>
> Meanwhile, on windows XP, I see it increase to around 20Meg, then sit
> around there until the GC.free, which brings it back down to around
> 5Meg, close to the starting point.
>
> Can anybody explain the difference here? Is the 14meg _really_
> unavailable to the OS in linux?

Ruby's garbage collector is conservative and walks the stack looking
for pointers into the heap. If it finds a possible pointer to the
heap the referenced memory will not be reclaimed. This can happen
even if you've returned from a method that referenced a large object.

> -------------
> class Grab
> def initialize
> @myhash={}
> 0.upto(100000) {|i| @myhash[i]="#{i} Im a part of a hash"}
> end
> end
>
> def memuse
> #IO.read("/proc/#{Process.pid}/status") =~ /VmSize.* (\d+) k/
> "Hi"
> end
>
> puts "Mem before anything: #{memuse}"
> sleep 10;
> 0.upto(10) do |x|
> t||=Array.new
> t[x]=Grab.new
> puts "Mem in scope #{x}: #{memuse}"
> sleep 1;
> end
> puts "mem out of scope #{memuse}"
> sleep 10;
> GC.start
> puts "Mem after GC: #{memuse}"
> sleep 10;

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...



Ronnie Bateman

12/16/2011 12:12:00 AM

0

Mason Barge <masonbarge@gmail.com> wrote:

> If West Side Story, Sound of Music
> and My Fair Lady are blockbusters, they aren't for stupid knuckledragging
> skateboarders just because they have a big box office. I think all three
> mentioned won Best Picture.

But they're still light entertainment that don't require any notable
smarts to enjoy. I'd estimate that films such as Dark Shadows, The Dark
Knight Rises and The Hobbit will be more "intellectually demanding,"
even if our newsgroup bitch oh-so-eloquently declares they are "shit."