What is the meaning of :FREE in ObjectSpace.count_objects on ruby MRI
We can find the meaning of :FREE
straight from the implementation itself (from gc.c )
* The keys starting with +:T_+ means live objects.
* For example, +:T_ARRAY+ is the number of arrays.
* +:FREE+ means object slots which is not used now.
* +:TOTAL+ means sum of above.
Then we can take a look at the tests for it (from test_gc.rb) :
assert_equal(count[:TOTAL]-count[:FREE], stat[:heap_live_slots])
assert_equal(count[:FREE], stat[:heap_free_slots])
And finally, we can double check there's no funny business going on with:GC.stat[:heap_free_slot] == ObjectSpace.count_objects[:FREE]
irb(main):001:0> GC.stat[:heap_free_slot] == ObjectSpace.count_objects[:FREE]
=> true
So, :FREE
indicates the number of allocated slots on the heap that haven't been used.
Is there a performance difference between `select` and `select!` when called on a Ruby hash?
select!
will perform better (I'll show the source for MRI, but it should be the same for the others).
The reason for this is that select
needs to create a whole new Hash
object, and will, for each entry in the hash, copy the entry - if the block succeeds.
On the other hand, select!
, will, for each key, remove the value - if the block doesn't succeed - in-place (with no need for new object creation).
Related Topics
Why Does the Rand() Return Always the Same Number
In Rspec, Using Let Variable Inside Before :All Block
How to Access a Symbol Hash Key Using a Variable in Ruby
How to Optimize Graphviz Output Width
Ruby Class Object Garbage Collection
Monitor Ruby Processes with Monit
Catching Command-Line Errors Using %X
Should Gemfile.Lock Be Committed to Source Control on Windows
How to Prevent Rails Controller Generator to Modify Config/Routes.Rb
Using Fork in Windows with Ruby
Require Ruby File Without .Rb Extension
Ruby - Naming Convention - Letter Case for Acronyms in Class/Module Names
Do I Need to Indent My Code in Ruby
When to Use Keyword Arguments Aka Named Parameters in Ruby
Ruby on Rails: Creating a Model Entry with a Belongs_To Association
How to Find Out All the Dependencies of a Gem
Controller Monkey Patch in Initializer Gets Lost When Rails Reloads Classes