title: Garbage Collection in C/C++ versus Java
body: <p>There is no Automatic Garbage Collection in C/C++.</p>
  
  <p>Assume that I wrote a simple program in C/C++ and created a single object.
  Assume that there are exactly 10 or extremely limited number of addresses for allocation.</p>
  
  <p>I have a for loop running for 100 times inside which this single object is created every time the loop is run.</p>
  
  <p>In Java, because there is Automatic Garbage collection, after a single loop is executed the address of the object is removed each time automatically.</p>
  
  <p>Rough Example:</p>
  
  <pre><code>for(int i = 0; i &lt; 100; i++)
  {
     Object o = new Object;
  }
  </code></pre>
  
  <p>In C/C++ we have to manually remove the Object address inside the for loop. Do we have to reboot each time as well to properly remove the Object reference in C++? </p>
  
  <hr>
  
  <p>For those who say that there are no problems deleting an object more than once in C++.  from Wikipedia:</p>
  
  <blockquote>
    <p>When an object is deleted more than
    once, or when the programmer attempts
    to release a pointer to an object not
    allocated from the free store,
    catastrophic failure of the dynamic
    memory management system can result.
    The result of such actions can include
    heap corruption, premature destruction
    of a different (and newly created)
    object which happens to occupy the
    same location in memory as the
    multiply deleted object, and other
    forms of undefined behavior.</p>
  </blockquote>
  
  <p>The link: <a href="http://en.wikipedia.org/wiki/Manual_memory_management" rel="nofollow">Manual Memory Management</a></p>
  
  <p>So there IS a risk?</p>