Page 1
Wink Notes
B.Tech CSE — 2nd Semester
Object Oriented Programming with C++
— Unit - 2 —
1. The Object Lifecycle
Just like any physical entity, every object in C++ goes through a definitive lifecycle: Creation, Usage, and Destruction. To manage this lifecycle securely, C++ provides special member functions.
Why do we need special functions?
When you create an integer `int x;`, it contains garbage value. When you create an object `BankAccount acc;`, it also contains garbage. If `balance` is a garbage value, any deposit or withdrawal is invalid. We need a guaranteed mechanism to initialize objects the moment they are created.
Memory Allocation
OS allocates physical RAM for the object's variables.
Initialization (Constructor)
Special function executes automatically to set valid initial states.
Usage
Application calls methods to interact with the object.
Cleanup (Destructor)
Special function executes to release resources before memory is reclaimed.
Deallocation
OS reclaims the physical RAM.