That’s basically the question. If I have a pointer int *a = &someIntVar and I do not delete it over the course of the program, does it stay in memory after the program has terminated? Is this a case of data fragmentation?
EDIT:
My mistake for using a bad example. So int *a = new int[100]; never gets deleted, and even if it gets deleted, an answer says that the pointee is deleted, not the pointer. Yet pointers also have a length. So the question is, on a Windows or Linux OS, does it automatically clean up after pointers? (Assume C++)
Since you have not
newed this pointer, you are not leaking memory.Were you to do
int* a = new int;and notdelete a, then you would leaka.As a rule of thumb, the number of
news should equal the number ofdeletes.When
someIntVargoes out of scope, the stack is unwound and its memory will be freed andawill be left dangling, of course.