Release what memory?
1 2 3
|
void dummy() {
int victim;
}
|
There was memory allocated from stack for the automatic variable 'victim'.
The "destructor" of an int is "empty", isn't it?
Yet, stack unwinding does release the memory at end of the function call.
1 2 3 4 5 6 7 8
|
class Raw {
double left;
int right;
};
void dummy() {
Raw victim;
}
|
It is still the stack unwinding that releases the memory that was allocated for victim.
The member variables were within that memory.
1 2 3 4 5 6 7 8
|
class Raw {
std::vector<double> left;
Raw() : left(42) {}
};
void dummy() {
Raw victim;
}
|
Still the same story. However, the constructor of victim did make the 'left' allocate memory for 42 doubles (dynamically).
The destructor of Raw has no explicit statements, but it does call the destructor of member 'left' that does call destructors of the 42 doubles (which is trivial), and then deallocates the dynamic memory block that the array did occupy.
Class destructor (even the default version) does call the destructors of the member variables and then the destructors of base class(es) after the body of the destructor.