Operating system handling of memory leaks?

Click For Summary

Discussion Overview

The discussion revolves around the handling of memory leaks by operating systems, specifically focusing on whether operating systems like Windows XP terminate processes when they detect memory leaks. Participants share experiences and technical insights regarding memory management and process termination related to memory allocation issues.

Discussion Character

  • Debate/contested
  • Technical explanation

Main Points Raised

  • One participant questions if operating systems kill threads upon detecting memory leaks, using a personal example involving dynamic memory allocation.
  • Another participant asserts that Windows XP does not terminate processes for memory leaks and suggests the crash may be due to unrelated reasons.
  • A third participant argues that if operating systems could detect memory leaks, they would not exist, explaining that operating systems do not track pointers to memory blocks and attributing the crash to the use of a dangling pointer.
  • A later reply clarifies that operating systems do not terminate processes for memory leaks but will shut down programs that attempt to access memory they do not own, mentioning segmentation faults and the behavior of Linux regarding excessive memory usage.
  • This participant also notes that some environments manage memory leaks differently, such as through garbage collection, which does not involve reference counting or C-style pointers.

Areas of Agreement / Disagreement

Participants do not reach a consensus on whether operating systems terminate processes due to memory leaks. Multiple competing views are presented regarding the causes of crashes and the capabilities of operating systems in managing memory.

Contextual Notes

There are unresolved assumptions regarding the specific conditions under which operating systems manage memory and the definitions of memory leaks and dangling pointers. The discussion also reflects varying levels of understanding of memory management techniques across different operating systems.

rohanprabhu
Messages
410
Reaction score
2
do some operating systems kill a thread as soon as it detects a memory leak? The operating system I'm talking about is Windows XP, in this case.

I had a small subroutine, that used to initialize a new variable [dynamic memory allocation], write some value to it and return the pointer [let's call it 'ptrInside']. When the function was called, another pointer was collecting it [let's call it 'ptrOutside'].

What happened is, when I call the subroutine once, it's fine. Because although the pointer declared in the function is killed, there is some variable i.e. 'ptrOutside' which was referring to the allocated space [let's call it 'gothSpace']. But when i called it the second time, 'ptrOutside' was now pointing to some other allocated space [let's call it 'blondeSpace']. So, now that the 'blondeSpace' was getting all the attention, and 'gothSpace' was lonely inside the memory, with no pointer referring to it.

What happened is that, Windows killed the process abruptly, with no reason whatsoever, being the conformist it is.

So, my question is that.. do some operating systems kill processes immediately when they detect that there is a goth in the heap about which nobody in the stack cares about?
 
Technology news on Phys.org
WinXP doesn't do that. The program may have crashed for unrelated reasons, though.
 
If operating systems were capable of detecting memory leaks, then memory leaks would not exist. No operating system keeps any kind of record of the number of pointers you make to any specific block of memory -- there's no system call involved.

Your program likely crashed because it tried to use a dangling pointer -- a pointer that refers to a block of memory your program no longer owns -- not because of a memory leak.

- Warren
 
rohanprabhu said:
So, my question is that.. do some operating systems kill processes immediately when they detect that there is a goth in the heap about which nobody in the stack cares about?

No. OSs will shut down programs that try to read or write to memory that they don't have access to. (This is called a segmentation fault in the Unix world.) Linux will also shut down programs that take up too much memory -- this may be an issue if you have a bad memory leak.

There are operating environments that will deal with memory leaks - programs loosing track of memory they've allocated, but they don't do reference counting, don't allow C-style pointers, and they won't crash in the way you describe. (You can look up garbage collection on google if you like.)
 

Similar threads

  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 15 ·
Replies
15
Views
7K
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
Replies
6
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K