[rspec-users] (Bad) Memory Leak in RSpec 2

David Chelimsky dchelimsky at gmail.com
Mon Feb 14 17:58:55 EST 2011

On Feb 14, 2011, at 20:20, Kane Baccigalupi <lists at ruby-forum.com> wrote:

> David Chelimsky wrote in post #981651:
> I am happy to get back to you about the documentation a little later. I
> want to take the time to fully describe the problems we had.

Much appreciated.

>> Please let me know what is not yet documented on the following pages:
>> http://relishapp.com/rspec/rspec-core/v/2-5/file/upgrade
>> http://relishapp.com/rspec/rspec-expectations/v/2-5/file/upgrade
>> http://relishapp.com/rspec/rspec-mocks/v/2-5/file/upgrade
>> http://relishapp.com/rspec/rspec-rails/v/2-5/file/upgrade
>>>   puts Johnson.evaluate <<-JS
>>>     Johnson.runtime.gc(); // trying to cleanup via JS
>>>   JS
>>> end
>>> We have tried a lot of ordering combinations in our garbage collection
>>> to see if anything will work, but instead the memory is climbing out of
>>> control with each suite. In version RSpec 1.x we didn't have to do any
>>> manual garbage collection.
>> Nor should you have to. Can you use after(:each) instead of after all?
>>  config.after(:each) { @dom = nil }
> We set up our @dom in a before :all block and reuse it through out the
> file. We don't want to eliminate it after each test, just once per
> block/file/whatever we set up.
> The problem isn't that the block isn't getting called at the right time.
> The problem is that dereferencing the instance variable doesn't seem to
> be releasing the variable for garbage collection like it was happening
> in version 1.x. We don't know why, and what might be different about
> RSpec 2 variable references.

The instance vars in after(:all) are copies, so setting them to nil there has no real effect. This was true in rspec 1 as well, so what you are experiencing is unrelated.

As a workaround, how about setting a global? Not a perm solution, but might get your suite working for the moment.

> More important, we are looking for a good
> solution, any solution, to the memory problem.
> -- 
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list