is there a way to delete a memory leak ?
like when the pointer is no longer pointing to that memory address, and that allocated memory is not accessible, how can i delete that ?
1 2 3 4 5 6
int *p = newint;
*p = 5;
//if i dont't delete p here, is that a way to deallocate the dynamically allocated variable above ?
p = newint; //since p is no longer pointing to 5, and there's no way of accessing it
*p = 10
delete p; //i know this only deallocates the memory address which holds 10, not the one before
When you detect them, it is a bug in your program. That is why it is called a memory leak, and why so many tools have been developed to find them so that they can be fixed. You need to stop the program, fix the leak, and rebuild the program. Then try again until there are no more leaks.