node深度循环,循环里面有插入数据的操作。回调一直不执行。然后报内存溢出
发布于 7小时前 作者 wustxing 61 次浏览 来自 问答

var s=new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24); var sql="INSERT INTO DoubleBall (redball,basketball) VALUES "; var e=0; var f=5000; for(var c=0; c< s.length-5;c++) { for (var b = c+1; b < s.length - 4; b++) { for (var a = b + 1; a < s.length - 3; a++) { for (var i = a + 1; i < s.length - 2; i++) { for (var j = i + 1; j < s.length - 1; j++) { for (var k = j + 1; k < s.length; k++) { for(var d=1;d<=10;d++) { e++; if(e<=f) { var txt = "[" + s[c] + “,” + s[b] + “,” + s[a] + “,” + s[i] + “,” + s[j] + “,” + s[k] + "]“; var doubleball = new DoubleBall({ redball: txt, basketball: d }); sql += "('” + doubleball.redball + “’,” + doubleball.basketball + "),"; if(e==f) { console.log(sql); doubleball.save(sql,function (err, doubleball) { if (err) { console.log(err); } else { console.log(“5000成功\n”); } }); f+=5000; } } } } } } } } } 报错FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

2 回复

这个用async.times 来代替吧,这个会造成内存溢出的

@kenshinhu 是的。就是报内存溢出错误。用aysnc.times怎么代替。。能详细点么

回到顶部