What happens to dereferenced heap pointers in C++?
If you have a class called A, I can allocate it both on the stack and on the heap. Let's say I allocated it on the heap like so: A* obj = new A; Now, in order to clean this data up, I'd have to delete it: delete obj; However, what if I decide to dereference this pointer and use it as if it was a normal object? A* obj = new A; A normal = *obj; Now I have a regular variable of type A. Now here is my question, does the heap allocation get cleaned up or not? I tested around and the destructor of A does in fact run, but I never called delete on this object, so is the memory still allocated or not? This is something I randomly thought of and I have no clue what the answer is. I have quite a bit of C++ experience and I'm surprised something like this causes me so much trouble.