ef4 / ember-elsewhere

Render elsewhere in the DOM, with nice composition, animation, etc. Based on 100% public API.
MIT License
184 stars 25 forks source link

Memory Leak #10

Closed sophypal closed 7 years ago

sophypal commented 7 years ago

I've been running into an issue where my acceptance tests would take up to 2GB on my machine running in Firefox. Taking a heap snapshot after all the tests run reveal a significant amount of memory being retrained by service:ember-elsewhere actives.

screen shot 2016-11-29 at 11 31 42 pm

In the screenshot above, most of the Arrays are from service:ember-elsewhere. I'm not sure where the problem lie. I have many tests that render a modal but doesn't close it after the tests are done. Is it possible that actives are not being cleaned up when the service is destroyed?

sophypal commented 7 years ago

Clearing out the contents of actives during destroyApp cleared the memory leak for me.

const emberElsewhere = application.__container__.lookup('service:ember-elsewhere')
Ember.run(function () {
  emberElsewhere.set('actives', null)
})
ef4 commented 7 years ago

This suggests that something else in your environment is retaining the entire container. If severing the link from the service to actives solves the problem, then your real problem is that the service itself is being retained, and the service is generally only retained because the whole container is retained.

In your screenshot, the yellow-highlighted function method() is probably the closure that is responsible. Often this is something like a global event handler.

sophypal commented 7 years ago

Thanks, I'll keep looking.

ef4 commented 7 years ago

Last time this came up it was a mouse-hover service. See https://github.com/ef4/ember-elsewhere/issues/6

sophypal commented 7 years ago

Unfortunately, it's not as clear-cut as that. None of objects in the retaining path resembles anything in my code but rather something deep inside ember-test-helpers and mocha.