sunspot/sunspot — Issue #108: memory leak when used with observer
Author: jeanmartin
Created: 2011-10-18 19:29:49+00:00
State: open

Hi,

Environment: Rails 3.1.1, Ruby 1.8.7 (REE)

Setup:

rails new app
cd app/
rails g model User name:string
rails g observer User

# add sunspot (master) to Gemfile:
gem 'sunspot_rails', :git => 'git://github.com/sunspot/sunspot.git'
group :test, :development do
gem 'sunspot_solr', :git => 'https://github.com/sunspot/sunspot.git'
end
bundle install

# add to config/application.rb:
config.active_record.observers = :user_observer

# add to app/models/user.rb:
searchable do
end

# add a simple text asset: app/assets/images/test.txt with content '.'

Now start up the app

rails c

And access the asset a few times:

for i in {1..500}; do curl http://localhost:3000/assets/test.txt; done

Watch the memory consumption of the server process rise. In a bigger app I can only load about 10 pages (with about 10 assets) before it needs about 1.5 GB. The problem goes away when I remove the "searchable" declaration from the User model or the observer line in config/application.rb.