Decrease flush_cache object allocations for the memoized methods.
Decrease flush_cache object allocations for the memoized methods.

Drop allocations by 43%.

Before

```
All allocations
18000 ~/Code/memoist/lib/memoist.rb:22 T_STRING  String
16000 ~/Code/memoist/lib/memoist.rb:6  T_STRING  String
12000 ~/Code/memoist/lib/memoist.rb:14 T_STRING  String
8000  ~/Code/memoist/lib/memoist.rb:14 T_ARRAY Array
4000  ~/Code/memoist/lib/memoist.rb:6  T_ARRAY Array
4000  ~/Code/memoist/lib/memoist.rb:22 T_NODE
2000  ~/Code/memoist/lib/memoist.rb:22 T_MATCH MatchData
300 ~/.rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems.rb:1120 T_STRING  String
100 ~/Code/memoist/lib/memoist.rb:74 T_DATA  Proc
100 ~/.rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54 T_STRING  String
100 ~/Code/memoist/lib/memoist.rb:74 T_DATA  RubyVM::Env
100 ~/Code/memoist/lib/memoist.rb:88 T_STRING  String
100 allocations.rb:45 T_ARRAY Array
Total: 64800
```

After:

```
All allocations
10000 ~/Code/memoist/lib/memoist.rb:22 T_STRING  String
8000  ~/Code/memoist/lib/memoist.rb:14 T_ARRAY Array
8000  ~/Code/memoist/lib/memoist.rb:6  T_STRING  String
4000  ~/Code/memoist/lib/memoist.rb:22 T_NODE
4000  ~/Code/memoist/lib/memoist.rb:14 T_STRING  String
2000  ~/Code/memoist/lib/memoist.rb:22 T_MATCH MatchData
300 ~/.rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems.rb:1120 T_STRING  String
100 ~/Code/memoist/lib/memoist.rb:74 T_DATA  Proc
100 ~/.rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54 T_STRING  String
100 ~/Code/memoist/lib/memoist.rb:74 T_DATA  RubyVM::Env
100 ~/Code/memoist/lib/memoist.rb:88 T_STRING  String
100 allocations.rb:45 T_ARRAY Array
Total: 36800
```

SCRIPT:

```ruby
def log_all_allocations(key = :line)
  require 'allocation_tracer'

  trace_keys = %i{path type class} if [:path, :file].include?(key)
  trace_keys = %i{line path type class} if key == :line

  ObjectSpace::AllocationTracer.setup(trace_keys)
  return_from_yield = nil
  result = ObjectSpace::AllocationTracer.trace do
    return_from_yield = yield
    nil
  end

  puts "All allocations"
  result.sort_by { |_, v| -v[0] }[0..200].each {|k, v|
    puts "#{v[0]}\t#{k[0]}:#{k[1]}\t#{k[2]}\t#{k[3]}\t#{k[4]}"
  }

  puts "Total: #{result.values.inject(0) { |count, v| count += v[0]}}"
  return_from_yield
end

require './lib/memoist'
require 'set'

$methods = Set.new
class Person
  extend Memoist
  1.upto(20) do |n|
    method = define_method("test_#{n}".to_sym) {}
    memoize(method)
    $methods.add(method)
  end

  1.upto(20) do |n|
    method = define_method("test_#{n}?".to_sym) {}
    memoize(method)
    $methods.add(method)
  end
end

p = Person.new
log_all_allocations(:line) do
  100.times do
    p.flush_cache
  end
end
```

matthewrudy/memoist