I know what both are, value and reference, but my question is why do both exist?
I mean why all primitives aren't also reference (or treated as such)? I know the primitives aren't affected by garbage collector, which i see as a drawback, and I can't find any pros to them, so what am I missing?
I mean why all primitives aren't also reference (or treated as such)? I know the primitives aren't affected by garbage collector, which i see as a drawback
Consider the following very common code:
for (var i = 0; i < 1000; i++)
for (var j = 0; j < 1000; j++)
Now imagine thats called once every second… that would be 1 000 000 reference types created every second that have to be allocated in the heap, kept track of, and collected by the GC. And you would see this as an advantage? Think again...