trifacta/vega — pull request #228 by codazzo (2014-12-28 12:48:15+00:00)
Title: Fix memory leak when rendering SVG's in headless mode (issue #221)

The leak is caused by the memoization cache in nwmatcher.
Every time vega calls d3.select(), d3 uses one of the available
DOM query methods exposed by jsdom [1], which in turn uses nwmatcher.
These queries are cached for efficiency [2] but if the cache is not
cleared, it grows with a jsdom node every time a new selector is used.
When vega does headless rendering, this means with every new render
as the ID's used in the selectors are incremental.
I discussed a possible fix with @dperini, who suggested calling
`NW.Dom.configure({ SIMPLENOT: true })` to empty the cache before
every new render ([3]).

[1] https://github.com/tmpvar/jsdom/blob/1.0.0/lib/jsdom/selectors/index.js
[2] https://github.com/dperini/nwmatcher/blob/v1.3.3/src/nwmatcher-noqsa.js#L692-L695
[3] https://github.com/dperini/nwmatcher/blob/v1.3.3/src/nwmatcher-noqsa.js#L348-L351