Christopher Smith wrote:
You might think that delete ptr fails to free up the memory allocated for Bar correctly, but point in fact you could cast ptr to a void* and invoke free() and it would do fine
I should clarify that one thing that *wouldn't* be fine about doing that is that Foo::~Foo() wouldn't get run. I was referring only to free() successfully cleaning up all the memory allocated for Foo. If Foo::~Foo() is defined, it is quite likely there are important resources that it cleans up that would NOT get cleaned up if you did free((void*)ptr), but the free would successfully deallocate sizeof(Bar) bits of memory and whatever additional memory the heap uses to manage said memory.

--Chris

--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to