4 ms·
If you want to reuse an object to avoid allocation, you better not have a reference to that object from somewhere else. In JS AFAIK there is no way to detect su
by pkolaczk 3y ago
If you want to reuse an object to avoid allocation, you better not have a reference to that object from somewhere else. In JS AFAIK there is no way to detect such situation automatically.
- Etheryte 3y agoYes there is, it's called scope and it's super easy to keep track of? In fact, you have to go out of your way to share a reference if you scope it.
- pkolaczk 3y agoIn languages like JS, Java, Python is trivial to accidentally make an object escape the scope by storing a reference in a field of another object that outlives the scope. And it can be another developer 3 months later that can introduce a bug, not knowing about your clever object reuse.