vendredi 28 septembre 2018

Ember-body-class initializer leaking memory

I found a memory leak in ember-body-class but don't know how to fix it best. The memory leak is in the ember-body-class initializer, namely in body-class.js line(42) and (58).

export function initialize(instance) {
  ...
  Route.reopen({

    ...

    addClasses: on('activate', function() {
  --> const document = instance.lookup('service:-document');
      const body = document.body;
      ['bodyClasses', 'classNames'].forEach((classes) => {
        this.get(classes).forEach(function(klass) {
          addClass(body, klass);
        });
      });

      ...
    }),

    removeClasses: on('deactivate', function() {
  --->const document = instance.lookup('service:-document');
      const body = document.body;

      ['bodyClasses', 'classNames'].forEach((classes) => {
        this.get(classes).forEach(function(klass) {
          removeClass(body, klass)
        });
      });

      ...

    }),
  });
}

The Problem is, please correct me if I'm wrong, that these lines are referencing the instance in the callback, so that there is a reference from the Route prototype to the instance, which in consequence retains the container. Finally, our unit tests run out of memory.

I already opened an issue at github too. Here's the link (https://github.com/crixx/bodyclassplayground) to my reproduction-repo. Steps to reproduce and trace the error are also in the repo-readme...

Anyone an idea how to fix this? Any help highly appreciated!




Aucun commentaire:

Enregistrer un commentaire