How much memory does a C# reference consume? Does References consumes memory as much as the object itself?
This is data for which memory is being allocated while executing the program. In C++, this allocation is usually performed by the malloc function or new operator. In 32-bit programs the size of dynamically allocated memory is restricted to 2 Gbytes, in 64-bit programs to 8 Tbytes.
-- We suggest that you set around 120 to 200 GB for the C drive. even if you install a lot of heavy games, it would be sufficient. -- Once you have set the size for the C drive, the disk management tool will start partitioning the drive.
Pointers take up the space needed to hold an address, which is 4 bytes on a 32-bit machine and 8 bytes on a 64-bit machine. In C++, every value is stored somewhere in memory and can therefore be identified with that address. Such addresses are called pointers.
reference variables (refs to other objects) take 4 or 8 bytes (32/64 bit OS ?) int16, Int32, Int64 take 2,4, or 8 bytes, respectively... etc.
A reference is implemented as a pointer, so in an application that runs in x86 mode (32 bit), a reference is four bytes, and in x64 mode (64 bit), a reference is eight bytes.
As the reference is just a pointer to an object, the reference is the same size regardless of what it is pointing to, or even if it doesn't point to anything at all (null).
From C# 5.0 in a Nutshell: The Definitive Reference in page 22;
Reference types require separate allocations of memory for the reference and object. The object consumes as many bytes as its fields, plus additional administrative overhead. The precise overhead is intrinsically private to the implementation of the .NET runtime, but at minimum the overhead is eight bytes, used to store a key to the object’s type, as well as temporary information such as its lock state for multithreading and a flag to indicate whether it has been fixed from movement by the garbage collector. Each reference to an object requires an extra four or eight bytes, depending on whether the .NET runtime is running on a 32- or 64-bit platform.
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