Skip to content

Instantly share code, notes, and snippets.

@hvrauhal
Last active August 29, 2015 14:08
Show Gist options
  • Save hvrauhal/321e2051a4bba294565e to your computer and use it in GitHub Desktop.
Save hvrauhal/321e2051a4bba294565e to your computer and use it in GitHub Desktop.
It would be nice if this did not consume all memory
var BPromise = require('bluebird')
var i = 0, n = 100000000;
function mapManyThings() {
return BPromise.map(new Array(1000), function () {
return BPromise.delay(1).then(function () {
i++
var aThousandFloats = new Array(1000).map(function () {
return Math.random()
})
return aThousandFloats
})
}).then(function (thisShouldBeGCd) {
process.stdout.write('\rshould garbage collect: ' + thisShouldBeGCd.length + ' random floats. Processed ' + i + ' batches of random floats')
})
}
function mapWithoutReferences() {
mapManyThings().then(function () {
if (i < n) {
process.nextTick(mapWithoutReferences)
}
})
}
mapWithoutReferences()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment