News for hackers. Stuff that matters.
Re:Chrome 59 has cross-platform headless support by Rumudiez on Wednesday April 12, 2017 @07:35PM (#14102736)
What do you do to ensure the resources for closed windows are released?
Re:Chrome 59 has cross-platform headless support by bluepnume on Wednesday April 12, 2017 @10:59PM (#14103789)
A combination of:

- Making sure all promises are fulfilled or rejected, so window objects don't get caught indefinitely in closure scope for any .then() or .catch() handler functions.

- Using WeakMaps as much as possible, when we have things that are tied to a particular window, like message listeners or response handlers in post-robot

- Manually clearing up any global references to windows when we destroy an xcomponent instance

Finding the references was the tricky bit. A lot of the effort was finding a leaky test-case, running in 100 times in succession, and deleting code until the memory graph was flat -- then figuring out what I'd just deleted that caused the leak.

The problem started manifesting as I added more and more tests -- so now I'm actually checking my tests' memory usage on the fly and failing if they cross a threshold. Hopefully that should avoid getting into this kind of sticky situation ever again.

https://github.com/paypal/paypal-checkout/blob/master/test/t...