Possible memory leak when switching routes
I'm using Ember 2.8.3. Every time I'm switching between routes there are some strange detached DOM trees inside the heap snapshop.
I've got a small repository (https://github.com/Haidy777/leaky-ember) which has two branches (master with 2.8.3, ember-2-9-1 with 2.9.1). Even when I'm switch between this "small" routes ("page1", "page2") I've got some of these detached elements.
Since the application which I'm working on is much more complex than this simple demo, there are even more detached elements. Which causes huge trouble on iOS-Devices (since they are very memory limited)
@locks What else do you need to verify this bug?
Even when I'm switch between this "small" routes ("page1", "page2") I've got some of these detached elements.
can you share some screenshots of what you see in the heap profiler and such? That helps makes sure all available information is shared to anyone working to confirm/diagnose.
Of course. I also added one of the snapshots into the repository mentiond above. After some switching between the two routes there are serval of this 'HTMLDivElement' and 'HTMLHeadingElement' visible. Some of them get cleared through the garbage collection, but not all. On this small scale it doesn't cost much memory, but as more content and more complex DOM gets changed, the footage grows.
To give you an overview: on one route we have a huge table with dynamically loaded entries which use the same component with some more nested components. On the other we have a medium sized grid which also gets dynamically loaded.
I will try to get the demo more clear to reproduce this problem better.

I just update the demo, now there are more Detached DOM trees when changing the routes:
Also there is another snapshot: https://github.com/Haidy777/leaky-ember/blob/master/Heap-20161201T143246.heapsnapshot
@locks @stefanpenner do you need a twiddle in order to verfiy this bug? if so, I could try to get this example running in a twiddle too.
Reproduction in app form as I believe you have added should be enough. I just have not had a chance to loook.
If I don't comment by mid-week feel free to pig me so I do :)
@stefanpenner alles klar, danke :)
FWIW I was unable to find any memory leaks after employing the three-snapshot method. Nor could I find a large number of detached red nodes after switching between routes a bunch of times like you could:

However, I looked at your heap snapshot file and found that the nodes are being retained in a property called triggerElement on some object. So I grep'd node_modules for that and behold:
$ grep -r triggerElement node_modules
node_modules/ember-basic-dropdown/addon/components/basic-dropdown/content.js: this.triggerElement = this.triggerElement || document.getElementById(this.triggerId);
node_modules/ember-basic-dropdown/addon/components/basic-dropdown/content.js: if (this.hasMoved || this.dropdownElement.contains(e.target) || this.triggerElement && this.triggerElement.contains(e.target)) {
Is it possible the memory leak is originating there?
@robbiepitts Thanks a lot, that seems possible indeed. I will file an issue over at ember-basic-dropdown and keep you guys updated.
I've investigated this in ember-basic-dropdown but I can't pinpoint how a memory leak can happen. It is true that I hold a reference to the "trigger" of the dropdown in the "content", but both components share the same parent and are destroyed at the same time, so those references should be garbage collected.
Also, i've checked and non-local events (those added to body/window) are cleaned in the willDestroyElement. I can't pinpoint what might be causing this problem.
I remember that at some point in history there was a bug in which the willDestroyElement hook was not invoked for contextual components, but I'd say that it was fixed before 2.9.1.
If someone with more experience in tracking memory leaks is available, I'd be happy to pair on this to see if we can find the leak.
@Haidy777 Do you have specific steps to reliably reproduce this with your demo repo? I've not been able to reproduce yet.
@robbiepitts Sorry for the late respone, I'm using following steps:
- open the demo
- click on
Page 1 - click on
Page 2 - repeat step 2 to 3 about 10 to 20 times
- take a heap-snapshot
@Haidy777 @stefanpenner @robbiepitts @cibernox @herom @locks is this still an issue, perhaps we should close or create a new reproduction of this, what do you think?
@pixelhandler I've checked the problem today with Ember 2.16. (as our Application was Updated to it). It doesn't seem to appear anymore so we could close this issue.
Thank you for the updated feedback!