admin管理员组文章数量:1401264
I work in an area where memory utilization is very important to us, as we don't run on your classic web browsers / hardware.
We use null quite a lot in our application, one thing that has not been clear to me is if null takes up more space than assigning a variable to undefined.
Do we know if one or the other is more costly on memory usage?
Thanks for help!
I work in an area where memory utilization is very important to us, as we don't run on your classic web browsers / hardware.
We use null quite a lot in our application, one thing that has not been clear to me is if null takes up more space than assigning a variable to undefined.
Do we know if one or the other is more costly on memory usage?
Thanks for help!
Share Improve this question asked Jun 14, 2018 at 10:07 mrkgreggmrkgregg 1231 silver badge4 bronze badges 2- Possible duplicate of Does null occupy memory in javascript? – user8214858 Commented Jun 14, 2018 at 10:14
- Check these answer: What reason is there to use null instead of undefined in JavaScript? – Yosvel Quintero Commented Jun 14, 2018 at 10:17
1 Answer
Reset to default 6As you can see in this jsperf test, null seems to be slightly faster in the chrome (V8, just like nodejs) which might indicate it being slightly more performant.
Since undefined is a longer string than null, the JIT piler has to save 4 bytes more to memory when using undefined instead of null while parsing. Consider that memory aswell.
The garbage collection doesn't care about the value being either null or undefined. The difference should be minimal. You should consider the consequences regarding types of using null instead of undefined though. Enforcing the usage of either for the sake of performance might do more harm than good.
本文标签: Javascript memory impact of null vs undefinedStack Overflow
版权声明:本文标题:Javascript memory impact of null vs undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744297836a2599429.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论