I have an array of nested objects populated in a loop.
Something like:
var myArray = [ object1: { //lots of nesting }, ... ] Now I run a loop over this and want to overwrite from index 1 after every loop iteration, example:
function getNestedObject(i) { //some object creation code } for (i = 0 ; i< 50000 ; i++) { var item = _.cloneDeep(getNestedObject(i)); myArray.push (item); if (myArray.length > 20) { //delete all elements and start pushing from scratch //Do i need to additionally destroy the items within each of these 20 objects being overwritten to avoid memory overflow? myArray.splice(0,20); } } This is required to avoid heap overflow due to heap space being gobbled up by the object array.
Do i need to additionally destroy the items within each of these 20 objects being overwritten to avoid memory overflow or automatic gc would happen within this scope?