This is a simple scraper written in JavaScript with Node.js, for scraping Wikipedia for periodic table element data. The dependencies are jsdom for DOM manipulation and chain-ga
I think I have a better work-around, reuse your instance of jsdom by setting the window.document.innerHTML property. Solved my memory leak problems!
// jsdom has a memory leak when using multiple instance
// cache a single instance and swap out innerHTML
var dom = require('jsdom');
var win;
var useJQuery = function(html, fnCallback) {
if (!win) {
var defEnv = {
html:html,
scripts:['jquery-1.5.min.js'],
};
dom.env(defEnv, function (err, window) {
if (err) throw new Error('failed to init dom');
win = window;
fnCallback(window.jQuery);
});
}
else {
win.document.innerHTML = html;
fnCallback(win.jQuery);
}
};
....
// Use it!
useJQuery(html, function($) { $('woohoo').val('test'); });