Sunday, 9 April 2017

True Way To Remove Property From Object (delete vs null vs undefined)

I have a big object with a lot of key-value pairs (like a dictionary). When something happens I want to remove key-value from this object. I'm aware of delete performance issue and also setting unused key to undefined/null looks like a good way but I'm still worried about GC. I can set object to undefined or null but key (property) still standing there and holds some memory. When I delete key, it disappears so I guess that means GC will free the key's memory. So it's confusing for me to find the true solution to remove key from a big key-value collection object. Maybe some suggestions or references?

Example:

var dic = {};

dic.a = 1234;
dic.b = "hello";
dic.c = "!#$";

delete dic.a;         // { b: "hello", c: "!#$" }
dic.b = undefined;    // { b: undefined, c: "!#$" }
dic.c = null;         // { b: undefined, c: null }



via MFatihMAR

No comments:

Post a Comment