Using variables in describe blocks in jasmine can cause memory leaks, e.g.:
describe('Memory leak', function() {
var a;
beforeEach(function() {
a = new Array(10000000).join('a');
});
it('test', function() {
expect(a).toBeDefined();
});
});
Due to internal design of the library such variables can not be collected by the garbage collector. Instead the suggested pattern to use is:
describe('Memory leak', function() {
beforeEach(function() {
this.a = new Array(10000000).join('a');
});
it('test', function() {
expect(this.a).toBeDefined();
});
});
The following are considered warnings:
describe('Foo', function() {
var foo;
beforeEach(function () {
foo = new Foo();
});
it('works', function () {
expect(foo).toBeDefined();
});
});
The following patterns are not warnings:
describe('Bar', function() {
beforeEach(function () {
this.bar = new Bar();
});
it('works', function () {
expect(this.bar).toBeDefined();
});
});