resides in memory; and the destructor uses a delete for that.
mc wrote:
Thanks Victor. I understand what you said and knew. Let me put more
context here but adding a more complete example:
void SKEL::bind(const MCU& mcu, ...)
{
// const FOO& MCU::foo()
// {
// return (*new Foo());
// }
FOO foo = mcu.foo(); // Because of the const FOO&
returned, foo becomes equal to what was returned by MCU::foo()
Yes. It becomes a copy of it.
// do stuff
// when exising here, the destructor for FOO is called and the memory
is release as per previous post
The memory for the object foo in SKEL::bind is, but there is the other FOO
object that was dynamically allocated. It's still hanging around, and you
lost all pointers to it, so you can't ever deallocate it. That's a memory
leak. With the destructor you described, you also happen to use delete
with
a pointer to memory you didn't get from new, which results in undefined
behavior.
}
The destructor for the object is only called once and no memory leaks
were
detected.
Sounds like your memory debugger has a problem.