as i understand, in windows, a memory leak occurs when you allocate some memory, but do not deallocate that memory before the programs exits. then that memory is lost to the windows machine until reboot.
does linux handle leaks the same way? or is the leaked memory somehow unallocated after the program exits?
I am talking about c++ new/delete operators, but i guess this applies to C as well.
thanks,
saai
In this respect, linux is just like windows. When a process requests the allocation of memory (through new, malloc, or whatever), the memory must be deallocated later. The OS has no way of knowing when to deallocate it. This allows different processes to share memory resources.
jemfinch
11-11-2000, 09:30 PM
Originally posted by saai:
as i understand, in windows, a memory leak occurs when you allocate some memory, but do not deallocate that memory before the programs exits. then that memory is lost to the windows machine until reboot.
does linux handle leaks the same way? or is the leaked memory somehow unallocated after the program exits?
Unless windows is completely braindead (and even if it is, really) it'll reclaim all memory from a process when it exits, whether that memory was deallocated specifically or not. As long as the program is open, however, it can't deallocate memory unless the process tells it to (with delete in C++ and free() in C).
Core programs in windows (like the kernel!) that are never intentionally restarted have had memory leaks in the past that have lead to instability. Since these programs don't exit, that memory actually is lost until a reboot.
Linux, however, has had few such memory leaks in recent years (actually, to be fair, "in recent years" windows hasn't had such problems either). Also, linux has fewer processes that can't be restarted; as long as the kernel, init, the swapper (can't remember the linux name) and the pagedaemon (likewise) don't have any memory leaks, you'll be fine; everything else can be restarted easily.
Jeremy