S
Sven C. Koehler
Hello,
could someone help me understand why this code leaks memory? (I am using
ruby 1.8.6 (2007-12-03 patchlevel 113) [x86_64-linux].)
def rss_leaks
/^VmRSS:\s+(\d+)/m.match(File.open("/proc/#{$$}/status") {|f|
f.read })[1].to_i
end
| irb(main):002:0> 100000.times { rss_leaks }; rss_leaks
| => 11624
| irb(main):003:0> 100000.times { rss_leaks }; rss_leaks
| => 16836
| irb(main):004:0> 100000.times { rss_leaks }; rss_leaks
| => 22008
| irb(main):005:0> 100000.times { rss_leaks }; rss_leaks
| => 27248
| irb(main):006:0> 100000.times { rss_leaks }; rss_leaks
| => 32468
Calling GC.start inbetween does not help, but when we rewrote rss_leaks
this way the leaks disappeared:
def rss_no_leaks()
d = File.open("/proc/#{$$}/status") {|f| f.read }
/^VmRSS:\s+(\d+)/m.match(d)[1].to_i
end
| irb(main):002:0> 100000.times { rss_no_leaks }; rss_no_leaks
| => 6568
| irb(main):003:0> 100000.times { rss_no_leaks }; rss_no_leaks
| => 6568
| irb(main):004:0> 100000.times { rss_no_leaks }; rss_no_leaks
| => 6588
| irb(main):005:0> 100000.times { rss_no_leaks }; rss_no_leaks
| => 6592
| irb(main):006:0> 100000.times { rss_no_leaks }; rss_no_leaks
| => 6572
Any help to further understand what actually causes these leaks would be
very appreaciated!
Best wishes,
Sven
could someone help me understand why this code leaks memory? (I am using
ruby 1.8.6 (2007-12-03 patchlevel 113) [x86_64-linux].)
def rss_leaks
/^VmRSS:\s+(\d+)/m.match(File.open("/proc/#{$$}/status") {|f|
f.read })[1].to_i
end
| irb(main):002:0> 100000.times { rss_leaks }; rss_leaks
| => 11624
| irb(main):003:0> 100000.times { rss_leaks }; rss_leaks
| => 16836
| irb(main):004:0> 100000.times { rss_leaks }; rss_leaks
| => 22008
| irb(main):005:0> 100000.times { rss_leaks }; rss_leaks
| => 27248
| irb(main):006:0> 100000.times { rss_leaks }; rss_leaks
| => 32468
Calling GC.start inbetween does not help, but when we rewrote rss_leaks
this way the leaks disappeared:
def rss_no_leaks()
d = File.open("/proc/#{$$}/status") {|f| f.read }
/^VmRSS:\s+(\d+)/m.match(d)[1].to_i
end
| irb(main):002:0> 100000.times { rss_no_leaks }; rss_no_leaks
| => 6568
| irb(main):003:0> 100000.times { rss_no_leaks }; rss_no_leaks
| => 6568
| irb(main):004:0> 100000.times { rss_no_leaks }; rss_no_leaks
| => 6588
| irb(main):005:0> 100000.times { rss_no_leaks }; rss_no_leaks
| => 6592
| irb(main):006:0> 100000.times { rss_no_leaks }; rss_no_leaks
| => 6572
Any help to further understand what actually causes these leaks would be
very appreaciated!
Best wishes,
Sven