int * pi = new int[64];
void* pv = (void*)pi;
delete[] pv;
Does this code produce memory leaks ?
new / delete short question
The memory of the array itself should be clean correctly, but if you do that with an object that allocated memory and deallocate it in the destructor, then you will leak, because the destructor called will be of the static type of the pointer.
this will call ~Test because the static type of pt is Test.
destructor called will be ~void. Doh! Test destructor is not called, so if Test allocated memory that was being deallocated in the destructor, you will leak.
|
this will call ~Test because the static type of pt is Test.
|
destructor called will be ~void. Doh! Test destructor is not called, so if Test allocated memory that was being deallocated in the destructor, you will leak.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement