Hey Vlad, nice to meet you 👋
>
> Any hints or learning materials to understand this behavior would be greatly appreciated !
I suspect these might be internal objects that the Ruby VM creates (for things like passing arguments, caches, etc).
Hopefully this gives a starting point for your investigation? ;)
-- Ivo
Hi everyone,
I have a curiosity regarding a simple ruby program stolen from this talk https://youtu.be/ZE6F3drGhA8?t=1811
<<EOF
def allocations
x = GC.stat(:total_allocated_objects)
yield
GC.stat(:total_allocated_objects) - x
end
p allocations { 1 }
p allocations { 1 }
EOF
Running this program with ruby version 2.7.8 works as I imagined reading it - both calls should print "0" to stdout (considering no allocations are happening in the provided block). However, running it with any ruby version starting from 3.0.7 (may not be the exact one introducing the behavior just what i tested with) I get strange results: first call to allocations outputs 1 and then any other future call to it outputs 0 as I initially expected. I get even stranger results with something like:
<<EOF
class A end
p allocations { A.new }
p allocations { A.new }
EOF
Ruby v2.7.8 outputs 1 for both calls, however from 3.0.7 onwards I see 5 being printed at the first call followed by 2 for future calls.
Any hints or learning materials to understand this behavior would be greatly appreciated !
Have a nice rest of the day / evening depending on your timezone
______________________________________________
ruby-talk mailing list -- ruby-talk@ml.ruby-lang.org
To unsubscribe send an email to ruby-talk-leave@ml.ruby-lang.org
ruby-talk info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-talk.ml.ruby-lang.org/