Seth's destructor answers
- memory allocated for the iarray and barray would remain in memory
with no way to access it.
- the iarray and barray would be deleted, but the two Bar objects
would remain in memory without way to access them.
- 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.
- 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.
- Everything is cleaned up. However, if the Bar objects had pointed
to some Foo objects the Foo objects would remain undeleted.
- The foo object pointed to by the Bar object in f->barray[0] would
remain undeleted with no way to access it.
- yes.
- 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