Code 1:
VaR array = [];
For (VAR I = 0; I <100000; I ++ ){
Array. Push ({name: "keatkeata "});
}
Code 2:
VaR array = [];
For (VAR I = 0; I <100000; I ++ ){
VaR OBJ = new object ();
VaR STR = new string ("keatkeata ");
OBJ. Name = STR;
Array. Push (OBJ );
OBJ = NULL;
}
The results of code 1 and Code 2 are the same.
But code 1 uses the memory of 6.xm and Code 2 uses 10 m.
Why?
In fact, this is similar to the principle of C.
STR is also an object that can also be represented by a pointer.
So code 1 is actually a new string ("keatkeat") once, and all subsequent references to the same object
Code 2, which is a new string many times, consumes a lot of memory!
JSON. parse uses 2nd methods, so you will find that there is not much consumption, and the result is more in JSON. parse!
Of course, if your strings are different, the browser won't be able to be optimized. Please be careful!