What Are Stack Heap Value Reference Types Boxing and Unboxing

When we move a reference type to a value type, the data is moved from the heap to the stack. This movement of data from the heap to stack and vice-versa creates a performance hit. When the data moves from value types to reference types, it is termed ‘Boxing’ and the reverse is termed ‘UnBoxing’.

What is stack & heap?

JVM has divided memory space between two parts one is Stack and another one is Heap space. Stack space is mainly used for storing order of method execution and local variables. Stack always stored blocks in LIFO order whereas heap memory used dynamic allocation for allocating and deallocating memory blocks.

What is boxing and unboxing What are the performance implications?

Boxing is the process of converting a value type to the type object or to any interface type implemented by this value type. When the CLR boxes a value type, it wraps the value inside a System. Object and stores it on the managed heap. Unboxing extracts the value type from the object.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest