The CLR contains a mechanism for automatic cleanup of objects called garbage collection. It
is important to understand how this system works, how it differs from other systems and how
your C# code can be as compatible as possible with this algorithm for the disposal of created
In C++, an object is created with the new keyword, and the operation returns a pointer to the
object as it is created on the application's memory heap. It is the responsibility of the C++
developer to explicitly release this memory by calling delete on that same pointer when the
object is no longer needed. Calling delete releases the memory used by the object and calls the
class' destructor so that the class could perform any class-specific cleanup operations.
Forgetting to call delete on an object pointer returned by new causes a memory leak.
In certain runtimes, such as Visual Basic and COM, objects are reference counted. The
runtimes keep a count of threads of code that attach to an object and automatically release the
object when its reference count reaches zero. This frees the developer from remembering to
call a destruction statement like delete and helps eliminate a whole class of bugs relating to
memory leak issues.
New Line Here...