I'm learning heap and I am told if we have to reassign a pointer to a new address, we have to delete the content in the address of the heap that the pointer points to, or that content becomes garbage and may cause memory leak. Like:
int* x = new int(10);
//delete x
x = new int(12) //without deleting x, the address that holds value 10 becomes garbage.
Therefore I'm thinking although the language doesn't have a GC, why the language is not updated with making a non-pointed heap address be able to be reallocated itself? So when the address is reallocated, the garbage content can be replaced with a new valid value, and therefore garbage collector can be omitted as well?
Thanks, and please point out if I'm wrong :)