node.js CALL_AND_RETRY_LAST分配失败 – 处理内存不足错误

我在for循环中遇到了这个问题,我的对象从xml中的xml2js中parsing出来,从mongoDB的'products'对象循环:所以我的代码在这里:

Product.find(function(err, products){ if(err)return updateDBCallback(err); if(products.length > 0) { products.forEach(function (dbProduct) { var equals = false; xmlFile.product_list.product.forEach(function (product) { var productEntity = new Product({ product_id: parseInt(product.id), parent_id: parseInt(product.parent_id), sku: product.sku, title: product.title, pricenormal: parseFloat(product.price_normal), pricewholesale: parseFloat(product.price_wholesale), pricewholesalelarge: parseFloat(product.price_wholesale_large), pricesale: parseFloat(product.price_sale), weight: parseFloat(product.weight), volume: parseFloat(product.volume), unittype: product.unit_type, status: product.status, datecreating: product.datecreating, sp: product.sp, guaranteeext: product.guarantee_ext, used: product.used, statusfull: product.status_full, description: null, url: null }); items.push(productEntity); if (dbProduct.product_id === productEntity.product_id){ log.info(" produt eqauls " + dbProduct.product_id + " =" + productEntity.product_id ); equals = true; } }); if (!equals) { log.warn("Remove PRODUCT " + dbProduct); Product.remove({ _id: dbProduct._id }, function (err) { if (err) return updateDBCallback(err); }); } }); 

所以在一些周期后,我得到了CALL_AND_RETRY_LAST Allocation failed - process out of memory ERROR错误。 我看到类似的问题,有人说什么-max_old_space_size参数可以解决这个问题。 但为什么会这样呢?

UPDATE1:我想我在items.push(productEntity);发现了这个问题items.push(productEntity); 所以我在我的分贝有5000个项目,在'xmlfile'有5000个产品,所以我的items数组增长到非常大的大小