Fix memory leaks / Add ember-cli-memory-leak-detector #1430
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR installs an add-on I authored called ember-cli-memory-leak-detector.
The add-on works by recording a heap snapshot after the suite tests finishes running. The heap snapshot is then searched for any retained instances of the host app/addon's ES classes (indicating a memory leak). If it finds retained classes in the heap snapshot, the test suite fails and a report of the retained classes is logged in the console output.
After installing ember-cli-memory-leak-detector (and fixing the few remaining leaky codepaths) we can ensure that no memory leak is ever introduced into EPS in the future, which is a big win for a such a popular addon!
I'll be giving a talk at EmberConf this year about ember-cli-memory-leak-detector and I'd like to get it installed in at least one or two popular addons prior to giving the talk. EPS was a great candidate because it is popular, already using ES classes, and the surface area of existing memory leaks seems limited. If ember-cli-memory-leak-detector gets traction from ember conf we can move the ember community toward eliminating memory leaks altogether!
To-Do
ember-cli-memory-leak-detector identified a few memory leaks that I haven't been able to fix on my own. I have narrowed down a few individual tests that exercise leaky code paths, however it's unclear whether it is the test itself that is leaky or the code that is being exercised that is leaking.
One common theme I noticed is that tests that exercise touch events on options seemed to be causing leaks. I did find that in a few of these tests, just triggering the
touchstart
event on an option was enough to cause the PowerSelect class to be retained, but I couldn't identify any obvious leaks in the event handlers for touch events.These tests can be isolated either via
ember test --filter="..."
or viaember test --server
and manually filtering in the browser test page, and ember-cli-memory-leak-detector will either fail or pass individual tests based on the heap snapshot generated after running the individual test.@triggerComponent
receives the@onFocus
action that triggers it