Lets say you have the following complex object:
var object1 = .... // (something complexed)
This takes up x
amount of memory i
Take a look at this question. Numbers, strings, etc. are always called by value, but objects are called by sharing; that is they are called by value, but the value is a reference to the object.
In other words, if you modify the pointer's properties, you are modifying the same pool of memory as the object. But if you reassign the pointer, it does not affect the original object.
What this means is that, in your example, you have not tripled the amount of memory that object1
took up, but the extra pointers to object1
will take up some memory space. Exactly how much space? That depends on the precise implementation of the Javascript engine, but it will always be much less than the size of the object.
As far as benchmarking goes, look at Mozilla's documentation for their JS engine, SpiderMonkey. There are lots of good utilities there....