Array Decay
A simple way to prevent increasing memory usage when iterating over objects that grow during their method calls, e.g. batch processing ActiveRecord objects that require lots of associated data.
Installation
Add this line to your application's Gemfile:
gem 'array_decay'
And then execute:
$ bundle
Or install it yourself as:
$ gem install array_decay
Usage
Simply call the #decay! method on your array before enumerating. This
instantiates and returns an enumerable ArrayDecay::Enumerator which
will unshift elements of the array.
moribund_objects.decay!.each do |item|
item.perform_expensive_operation!
end
moribund_objects.count # 0
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request

