Object allocation and deallocation
Let’s look more in-depth at how object allocation and deallocation work in programming and what happens behind the scenes. Before we get into the programmatic aspects of allocation and deallocation, we must first understand and appreciate what an object is and why it is an essential construct in programming.
Objects and how they are created
An object is an instantiation of a class in object-oriented programming (OOP). In every programming language, we construct a variable, which is used to store data between operations in a program. A variable is declared to have a type and a name. The types that can be used are as follows:
- Value type: Uses primitive types such as
bool
,int
, andchar
. Variables defined by these types hold data in their location. - Reference type: More complex data types, such as classes, arrays, and delegates. These contain pointers to a memory location that holds the data.
Value-type variables are the...