Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Memory Leak] beforeEach / afterEach appear to leak #841

Closed
stefanpenner opened this issue Aug 4, 2015 · 1 comment
Closed

[Memory Leak] beforeEach / afterEach appear to leak #841

stefanpenner opened this issue Aug 4, 2015 · 1 comment

Comments

@stefanpenner
Copy link
Contributor

the following code (from : source) appears to leak beforeEach and afterEach on the original module. This results in per module leak of the ambient context.

this.testEnvironment = extend( {}, this.module.testEnvironment );
delete this.testEnvironment.beforeEach;
delete this.testEnvironment.afterEach;

Obviously the following, prevents the leaks:

var foo;

module('test', {
  beforeEach() {
    var foo = new Foo();
  },

  afterEach() {
    foo = null
  }
});

but it is tedious and error prone. A much better solution, for those using modules (AMD/CJS/etc), is merely to release the entirely module. Unfortunately, QUnit retaining beforeEach and afterEach per module, prevents a less error prone and tedious solution.

cc @cibernox

@stefanpenner
Copy link
Contributor Author

A quick spelunk indicates the above offending code is likely just run in the wrong order and incorrect object.

if:

this.testEnvironment = extend( {}, this.module.testEnvironment );
delete this.testEnvironment.beforeEach;
delete this.testEnvironment.afterEach;

becomes:

delete this.module.testEnvironment.beforeEach;
delete this.module.testEnvironment.afterEach;
this.testEnvironment = extend( {}, this.module.testEnvironment );

We release as expected, without any leaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant