Seth's destructor answers

  1. memory allocated for the iarray and barray would remain in memory with no way to access it.
  2. the iarray and barray would be deleted, but the two Bar objects would remain in memory without way to access them.
  3. The Bar objects would be cleaned up, so would the iarray, but the barray pointed to by f would remain in memory without any way to access it.
  4. after deleting the barray we know longer can count on the values that were stored in it. Thus, the for loop may try and delete arbitrary addresses.
  5. Everything is cleaned up. However, if the Bar objects had pointed to some Foo objects the Foo objects would remain undeleted.
  6. The foo object pointed to by the Bar object in f->barray[0] would remain undeleted with no way to access it.
  7. yes.
  8. When a pointer, p, to type X is deleted, if type X has no destructor then the memory that p points to is returned to the heap. Thats it. If type X has a destructor defined, then the destructor is invoked, doing whatever it indicates, and when the destructor returns, the memory is returned to the heap

Seth's destructor answers / C++ language / Review questions / 15-211 A, B