Quick question about memory leaks

So, if I'm remembering correctly, failing to delete memory allocated with new will cause the memory to remain in the system after the program ends. I'm fairly certain this memory is in the RAM, so would fully restarting the computer delete this? If not, is there any way to remove this from my system, or does it just sit there taking up space? I'm on a MAC, if thet helps.
Last edited on
Definitely. When the computer is restarted, it reallocates entire memory allocation. Don't you loose unsafe files if you reboot? :)

I think that undeleted memory also goes to unallocated pool when the process ends. I am not 100% certain about this. Someone else, please confirm. Thanks!
closed account (zb0S216C)
"So, if I'm remembering correctly, failing to delete memory allocated with new will cause the memory to remain in the system after the program ends."

Correct. Usually, if the leak is small enough, the operating system will find and deallocate the memory before it can grow. Though, not all operating systems support this feature.

Whovian wrote:
"I'm fairly certain this memory is in the RAM"

Not always. Depending on the allocation method, memory can be allocated from different parts of the system. Some areas of memory, such as graphics memory, would require allocation through the operating system's API. In fact, some areas of memory are simply off-limits.

Whovian wrote:
"so would fully restarting the computer delete this?"

As I said, it depends where you allocated the memory. Some places may (and I use that word loosely) not be affected by restarting, though, this is highly unlikely.

Wazzak
Last edited on
So, if I'm remembering correctly, failing to delete memory allocated with new will cause the memory to remain in the system after the program ends.


I'm not convinced that is a true statement. You might want to research some other message boards about that. Of course it is better to cleanup so that you don't have to worry about the answer. I believe that the heap is allocated to the program and that when the program ends, the entire heap for that program is returned to the system. I'm not sure why you would need to reboot for that memory to become available to another program.
To my understanding, the allocated memory is deleted once the the program is ended.
It is because of this that some programmers will not delete dynamically allocated memory if that memory must exist until the end of the program.
This is probably why stopping processes via task manager, or kill does not break your computer.
kempofighter, I took your suggestion, googled it, found some more information on Stack Overflow.

Again, thanks, everyone, I was just wondering if some of my old objects might still be hanging around from back when I didn't have any idea what new meant.
If your program is running inside of any operating system whose creator should not be killed mercilessly, then said operating system will not leave any memory marked as occupied / in use, if it was allocated for a process that has ended. :)

Effectually, memory leaks are only a big problem when you have a long-running application or daemonized process which doesn't "take out the trash" and over time wastes the memory away. However, even in programs which end quickly, it is good/clean practice to de-allocate any heap space you use, once you are finished with it.
Topic archived. No new replies allowed.