1
var func2= function(a) {
    var prop = a.prop;
    
    var temp = getJson(prop.innerProp);
    if (temp) {
      a.val = temp;
    }
}


var func1 = function(a) {
    var prop = a.prop;
    prop.innerProp = a.val;
}


var a = {// some properties;
        };

func2();
func1();

Is there cyclic refernece in a obj? I think there is and does it cause memory leak in nodeJs?

Is memory leak by cyclic refernce is corrected in node 18 version?

Does this memory leak increase RSS and heapUsed?

  • Circular references don't cause memory leaks in Javascript, this is because it uses a GC (Garbage Collector). – Keith Feb 22 '23 at 10:37
  • @Keith https://stackoverflow.com/questions/1493453/example-of-a-circular-reference-in-javascript it's pointed out that Javascript GC has issues with cyclic reference. Not sure, if it's resolved in the newer version. I am using node version 8. – Shubham Pareek Feb 22 '23 at 11:31
  • Are you still writing code for IE6 & below?. NodeJS uses Chrome's V8 engine, and as far as I know has never had issues with circular references. I remember when Microsoft went it's own way and decided using reference counting was a good idea, and one big issue with reference counting, it can't handle circular references. In IE6 and below, even this would have been a memory leak -> `var a = {}, b = {a}, a.b = b;` – Keith Feb 22 '23 at 11:35

0 Answers0