I was just thinking what happens when we use free() with new in C++.
In case if we use free() with new then the memory could be freed. Its just the destructor will not be called. Leaving behavior something like similar to dangling pointer.
I understand that above we should not use free() with new as it may corrupt the heap.
But then also I would like to visualize the behavior conceptually.
Using
freeon memory allocated bynewis undefined behavior. There’s no guarantee thatnewreturns an address returned frommalloc. (In fact,new[]often doesn’t.)