views:

71

answers:

2

Hello.

  • What are the effects of not detaching a Shared Memory Segment?

  • How different operating systems handle this?

  • Can not detaching compromise the stability of the O.S?

Thanks.

+1  A: 

Not detaching will prevent others from deleting the memory segment, this is true on windows and on linux. Thus you will have a memory leak. It wont compromise the stability of the O.S but why won't you want to detach and delete the segment once you finish using it ?

daniel
A: 

If shared memory segment is not detached then the kernel keeps on thinking that the particular segment (kernel call it region) is in use and would never mark it for deletion - kind of reference counting mechanism is used internally. Another problem, would be that process' virtual address space would be eaten up unnecessarily.

However, I am not sure if we can call it memory leak (Java people would say, although) because this memory segment would be detached and freed automatically the moment process exits.

This may not compromise OS as a whole, but system may have to close - that too without any notice - some processes that are eating a huge memory if it goes out of memory( See Linux OOM killer). But this is the worst case.

Raman Chalotra
@Raman Chalotra, thank you for your answer, I've tested this under Linux (Ubuntu), and it doesn't automatically frees when the process exits.
Liran Orevi