Some refer to the dynamic memory resource as "Free Store". It may be a heap. (There can be more than one heap in a system.)
The
new
and
delete
do more than just allocate and deallocate block of raw memory.
They also construct and deconstruct objects within that block.
Placement new
does not even allocate the memory, but construct object into given space.
The
delete myTuple;
thus invokes the destructor of
tuple<int*,myClass*>
first and then deallocates the memory block.
The answer to
// will that delete the contents of "myTuple" as well? |
depends thus on the destructor of std::tuple. I'd say "no".
Technically, the "content" of "myTuple" is just two pointers and trivial destruction of pointer is a no-op.
There is both
new
that creates one object and
array new
that creates an array of objects. You cannot mix the two and have to use corresponding
delete
too (for single or for array). You make the error of creating one object but assuming that you have an array.
Automatic variables, variables declared within a (function) scope, have memory allocated from stack on call of the function/entry to scope and are automatically destroyed and deallocated at end of the scope. You return an address of automatic variable from function.
You change a pointer to point from one object to an another. You can't access the first object after that.
Assignment is not initialization. Not an error here, but a bad habit.