Created
October 17, 2019 00:56
-
-
Save bryanp/bd28b18f7facc19f0819a27c63f3b408 to your computer and use it in GitHub Desktop.
Ruby allocation calling mixin
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
module Foo | |
def foo | |
bar | |
end | |
def bar | |
end | |
end | |
class Whatever | |
include Foo | |
end | |
class SomethingElse | |
def foo | |
bar | |
end | |
def bar | |
end | |
end | |
something_else = SomethingElse.new | |
start = GC.stat(:total_allocated_objects) | |
something_else.foo | |
puts GC.stat(:total_allocated_objects) - start | |
# => 0 (this is what I expected) | |
whatever = Whatever.new | |
start = GC.stat(:total_allocated_objects) | |
whatever.foo | |
puts GC.stat(:total_allocated_objects) - start | |
# => 2 (huh)? |
That means it can't be a Ruby object but some internal data structure allocated by Ruby.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using
rspec-memory
to capture this but didn't get any clear picture.gives