Skip to content

Instantly share code, notes, and snippets.

@RashneetR
Created December 8, 2020 05:50
Show Gist options
  • Save RashneetR/c6c505d548dc1a453815799bc67c8dd4 to your computer and use it in GitHub Desktop.
Save RashneetR/c6c505d548dc1a453815799bc67c8dd4 to your computer and use it in GitHub Desktop.
Garbage collection Example with Ruby Version
# This script shows how garbage collection is done for symbols Ruby 2.2.1 onwards
# Ruby 2.1
100_000.times do |i|
"sym_#{i}".to_sym
end
# => 100000
before = Symbol.all_symbols.size
# => 103318
GC.start
# => nil
after = Symbol.all_symbols.size
# => 103318
# Ruby 2.2.1
before = Symbol.all_symbols.size
# => 3892
100_000.times do |i|
"sym_#{i}".to_sym
end
# => 100000
before = Symbol.all_symbols.size
# => 5535
GC.start
# => nil
after = Symbol.all_symbols.size
# => 3892
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment