Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added fix for the memory leak and a test example from a discussion ab…

…out the issue.
  • Loading branch information...
commit 127ceb73ec4649e107048b0e892894a04abe340e 1 parent 2e10ee3
@vermiculite vermiculite authored
Showing with 42 additions and 1 deletion.
  1. +2 −1  main.js
  2. +40 −0 tests/memory_leak.js
View
3  main.js
@@ -195,7 +195,8 @@ Spider.prototype._handler = function (url, referer, response) {
} else {
r.fn.call(r, window, window.$);
}
- this.currentUrl = null;
+ this.currentUrl = null;
+ window.close(); //fix suggested by
}
}
Spider.prototype.log = function (level) {
View
40 tests/memory_leak.js
@@ -0,0 +1,40 @@
+/**
+ * AS taken from this gist https://gist.github.com/gmarcus/934787
+ * original dies after 840 fetches
+ * @type {*}
+ */
+
+var sys = require('sys');
+var util = require('util');
+var spider = require('../main');
+var counter = 0;
+
+spider()
+ .route('itunes.apple.com', '/us/genre/*', function (window, $) {
+ if (this.fromCache) return;
+
+ console.log("Fetching page: %s, for the %s th time", this.spider.currentUrl, ++counter);
+
+ // spider all genres
+ $('div#genre-nav.main.nav a').spider();
+
+ // spider all letters per genre
+ $('div#selectedgenre ul.list.alpha li a').spider();
+
+ // spider all numbered pages of letters per genre
+ $('div#selectedgenre ul.list.paginate li a').spider();
+
+
+ // // fetch apps JSON and store in a database (not implemented yet)
+ // $("#selectedgenre .column a").each(function(i,a) {
+ // // extract the iTunes URL
+ // var aHref = a.href;
+ // console.log("Recording " + aHref);
+ //
+ // });
+
+// console.log(util.inspect(this.spider, false, null));
+ })
+ .get('http://itunes.apple.com/us/genre/ios/id36?mt=8')
+ .log('info')
+;
Please sign in to comment.
Something went wrong with that request. Please try again.