C
Chuck Remes
My basic understanding of the garbage collectors in use by the various Ruby runtimes is that they all search for objects from a "root" memory object. If an object cannot be reached from this root, then it is collected.
Here's a snippet of ruby code. I'm not sure how the GC will treat it.
class Foo
def initialize
@baz = Baz.new
@quxxo = Quxxo.new
end
end
class Bar
def run
Foo.new
nil
end
end
bar = Bar.new
bar.run
bar.run
bar.run
What happens to the instances of Foo created in the call to #run? Since I am not saving them somewhere (e.g. to an array), do they get collected right away?
If the Foo instances get collected, is it safe to assume the Baz and Quxxo instances are being collected at the same time? Does their existence prevent the Foo instance from being collected?
cr
Here's a snippet of ruby code. I'm not sure how the GC will treat it.
class Foo
def initialize
@baz = Baz.new
@quxxo = Quxxo.new
end
end
class Bar
def run
Foo.new
nil
end
end
bar = Bar.new
bar.run
bar.run
bar.run
What happens to the instances of Foo created in the call to #run? Since I am not saving them somewhere (e.g. to an array), do they get collected right away?
If the Foo instances get collected, is it safe to assume the Baz and Quxxo instances are being collected at the same time? Does their existence prevent the Foo instance from being collected?
cr