unless @extend
class Hash
include BetterHash
end
end
t = Time.now
1_000_000.times do
s = {}
s.extend BetterHash if @extend
end
after = Time.now - t
puts "done with #{GC.count} gc runs after #{after} seconds"
sleep # so that it doesn't exit before we check the memory
=begin
I think you can tell if it was a leak by running a loop
loop do
s = {}
s.extend BetterHash if @extend
end
If this eats up all memory in the system then it's a leak. [on mine it stays constant at 4MB].
That doesn't mean to say there's no bugs in there, though--it may be the case that you're using up the entire freelist each time, without ever passing the malloc_limit, which means that your heap total size will get bigger and bigger and bigger...not sure though.
Compiling 1.9 with the GC stats turned on might help.
Cheers!
-=r
=end
=begin
I've just tried the code above with Ruby 1.9.2 Preview 1 and the current trunk.
I can confirm that this doing
./ruby leak_test.rb LEAK
on the above versions appears to leak memory as ps aux / top reports a 0.8% memory utilization by the time the script has finished running. The memory usage goes up gradually as the program runs. Once the program has hit the sleep command, the memory usage does not go down, even if a GC.start call has been inserted directly above to coerce the Ruby VM to clean up.
Running this under the current 1.8.8 snapshot does not to this, and the memory usage remains constant throughout. Likewise not passing any arguments (so extend is not called) also keeps the memory usage constant under both 1.8.x and 1.9.x branches tested on my system.
I am running an a 64 bit (x64) bit rather than a 32bit (x86) build.
=end
=begin
And just to confirm, using an indefinite loop like Roger points out makes my Ruby process grow continuously. After about 6-8 minutes my Ruby process had grown to 12% of memory usage and showed no sign of going down.
=end
While I'm no C guru, I'm guessing the issue will be relating to include_class_new in class.c or at least it doesn't look like a garbage collection issue given that your clone seems OK.
=end
=begin
This issue was solved with changeset r26515.
Muhammad, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.