The Object Life Cycle
Creating an object: You use the new keyword to instantiate the new object.
- A block of memory is allocated. This block of memory is big enough to hold the object. (CLR handles the allocation of memory for managed objects)
- The block of memory is converted to an object. The object is initialized. (You can control this step by implementing a constructor)
Destroying an Object: You use destruction to reclaim any resources used by that object.
- The object is cleaned up; for example, by releasing any unmanaged resources used by the application, such as file handles and database connections. (You can control this step by implementing a destructor.)
- The memory used by the object is reclaimed.
The CLR handles the release of memory used by managed objects; however, if you use unmanaged objects, you may need to manually release the memory used by these items.