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 not delete a, then you would leak a.
As a rule of thumb, the number of news should equal the number of deletes.
When someIntVar goes out of scope, the stack is unwound and its memory will be freed and a will be left dangling, of course.
No, all memory allocated by the process is usually freed when the process terminates. But this may not be the case for stuff like file handles or graphics resources (i.e. in Win32 device context handles, bitmaps etc.).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With