11.3 delete Keyword


11.3 delete Keyword

To delete an object created with the new keyword from memory, the delete keyword can be used. For each object created with new there should be a corresponding deletion using delete. Otherwise, objects not deleted are sometimes left lingering in memory, hogging more and more resources. This is called a memory leak, which can be the cause of many errors. Consider the following code for the creation and deletion of an object in memory.

      #include <iostream>      int main()      {         int *Number = new int;         *Number = 5;         std::cout<<*Number;         delete Number;         return 0;      } 




Introduction to Game Programming with C++
Introduction to Game Programming with C++ (Wordware Game Developers Library)
ISBN: 1598220322
EAN: 2147483647
Year: 2007
Pages: 225
Authors: Alan Thorn

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net