I'm not even sure if I'm using the right terms here, but if I have a code like this: (in C#)
Object object1;
Object object2;
object1 = new Object();
object2 = object1;
Will object2 take up as much space as object1, or just point to the instance created at object1?
If I'm not using the correct terms to express myself properly, by all means tell me as well.
A reference takes exactly one word of memory. That's 32 bits in a 32 bit application, 64 bits in a 64 bit application, etc.
Both variables take up exactly one word of memory, since they are of reference types. There is also some amount of memory, somewhere, that holds however much is needed for one actual object instance. Both of those variables in your program happen to contain a reference to that object, but they'd take up the same amount of space even if they didn't. (A null reference takes up the same space as a valid reference, after all.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With