I think there can be a difference between browers,
but how do I find out how much memory an array or one element of it takes in Javascript?
I want to figure out how much space I save when using a typed array.
Thanks in advance!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This depends on a wide number of aspects.
The reality is different. You shouldn’t worry much about client side storage. Not in this way at least. The only memory specific control you really need is memoization. Other than that, all you need to do is to clean up your traces, so to speak. If you are in an OOP environment, make sure to always
deleteinstance references and null yourCOMandDOMreferences once you are done with them.If you wish to empty a collection (array), simply use the
deleteoperator. If you are not defining the collection as an instance property, but instead you are usingvaras defining it as a context variable, usemyArray.length = 0;which willdeletethe entire storage in the array.If you are dealing with large collections, direct assignment is faster than using the
Array.prototype.push();method.myArray[i] = 0;is faster thanmyArray.push(0);according to jsPerf.com test cases.The amount of time it takes to iterate over an array can vastly change depending on how you reference the array length, as well as the internet browser you use.
Test cases for the above are available here.
As of June 6, 2015, the relative speeds are as follows:
When defining arrays, there is absolutely no point to specify the length, especially if you are doing deferred initialization.
Test cases for array definition are available here.