Memory Leakage with before :all blocks #312

Closed
baccigalupi opened this Issue Feb 15, 2011 · 10 comments

Projects

None yet

7 participants

We are using Harmory and RSpec to javascript tests that are deeply integrated with our Ruby views. We created a version of the Harmony that reduces memory significantly at the cost of performance. Typically we see 120 MB of usage per Harmony related spec file. We were using version 1.x of RSpec but have just switched up to 2.5. Our setup is like so:

describe 'some javascript class' do 
  before :all do 
    @dom = Harmony::Page.new(my_ruby_view) 
    @dom.load(some_js_files) 
  end 
  it 'should do something' do 
    @dom.execute_js('javascript here').should == what_we_expect 
  end 
end 

We are running into a problem where the @dom variable is never released. As such our memory usage grows and grows with each new harmony test file. Since we have over 1500 javascript tests, the growth in memory usage crushes our development computers quickly.

We were running this suite in version 1.x and had no trouble with the garbage collection after changing the Harmony gem. We have temporarily switched to a global variable, $dom, at David's suggestion. It has resulted in the memory recovery that we experienced in version 1.3.

Although Harmony memory usage is our main concern, we are also seeing memory leakage with
our entire test suite which has over 6200 tests, almost all of which include variable setup in a before :all block. We saw a memory loss leakage of about 850 MB. Normally, we only see memory usage of about 150 MB which mostly was lost in Harmony specs.

Here is the group conversation about the issue:
http://groups.google.com/group/rspec/browse_thread/thread/686d392dbcef106f

Owner

#321 has additional information on this.

Owner

ff18091 clears ivars declared in before(:all). I think this solves baccigalupi's issue, but not carllerche's (so maybe they're not duplicates after all).

@baccigalupi - can you verify that your issue is resolved by that commit?

Sorry for the delay. I was out of the office for quite a while.

Unfortunately, this patch did not fix my memory leak. I am still seeing it increase with each suite.

I am running rspec bundled from git, last commit 51cb016

jensb commented Mar 22, 2011

I have a similar problem. After upgrading to 2.5 (from 1.3) due to a Rails upgrade from 2.3.10 to 3.0.5, running my specs makes RAM usage climb up to about 800 MB.
I patched ff18091 into my rspec-core but it didn't help.
After observing ObjectSpace, it seems that any variable I declare in any test will be kept in memory. After running 200 tests for a fairly large model, in the "after(:all)" block over 200 instances of this model were still in memory - even though I never used instance variables (i used normal local variables in my "it" blocks).

Please investigate this, I will help where I can, but currently we cannot practicably run our tests in this situation.

Contributor
Peeja commented Nov 21, 2012

A wild triage fairy appears!

@baccigalupi, @jensb, are you still seeing this issue?

Contributor

A wild triage fairy appears!

Thank you @Peeja! I'll wait a week or so and close if no more info is available.

jensb commented Nov 22, 2012

No ("ruby" starts off with ~120MB and ends up with about 220MB of memory usage after 1800 tests). Thank you!

Thanks @Peeja . I am not part of the project that was having this problem. @cohuman will be able to answer this. I will give them a shout, or you can reach out directly.

@Peeja, we're no longer seeing the issue on the @cohuman project, but this is most likely because we're no longer using Harmony (switched to Jasmine).

Contributor

Looks like those who reported the issue are no longer having problems with it, I suggest the issue be closed.

@alindeman alindeman closed this Dec 6, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment