Created
September 19, 2012 05:20
-
-
Save JoshCheek/3747823 to your computer and use it in GitHub Desktop.
Ruby gc not collecting array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
THE_STRING = 'a random 369-characterish string' | |
def self.find_array | |
ObjectSpace.each_object Array do |array| | |
return array if array.any? && array.all? { |s| s == THE_STRING } | |
end | |
nil | |
end | |
def self.print_whether_array_exists | |
if array = find_array | |
puts "IT EXISTS WITH SIZE #{array.size}" | |
else | |
puts "IT DOES NOT EXIST" | |
end | |
end | |
array = [] | |
require 'time' | |
time = Time.now + 2 | |
array << THE_STRING while time > Time.now | |
print_whether_array_exists | |
array = nil | |
GC.enable | |
GC.start | |
print_whether_array_exists |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like a bug in MRI to me:
Rubinius GC's it as expected: