Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In other words, process A uses a mem-page and writes data to it, then frees it (or crashes without freeing), then process B is allocated memory from that page, will process B see data written by A?

If not, and the OS clears the page, why do I see random data in memory? For example, when executing:

int i;

i contains some random value, usually not 0x00000000 or 0xffffffff.

This question came up when studying for an Operating Systems course, so it relates to what an OS is "supposed" to do.

share|improve this question
2  
You're really going to ask this 'question' and not even give us a vague hint about what OS you're talking about? Let me guess; OS/2 v1.1, you know the first one with Presentation Manager, or maybe BeOS, unlikely I know, how about OS/370? no? I give up... – Chopper3 Jul 1 '11 at 12:16
1  
Actually, this question is meaningless for OS/2 v1.1. The first version of OS/2 to use paging was OS/2 version 2.0. Ironically the behaviour observed has little to nothing to do with how the operating system initializes pages, and if the questioner hadn't built a bogus assumption into the question it could have been asked of OS/2 v1.1 even though that used segmentation. That would have led to the right answer and avoided the wild goose chase that the questioner is sending us on. – JdeBP Jul 1 '11 at 12:24
1  
@JdeBP - man I frickin' love SF some days :) - incidentally I worked on OS/2 v2.0 - long time ago, looooong. – Chopper3 Jul 1 '11 at 12:29
@JdeBP, what does paged memory have to do with an OS clearing memory contents before an application uses the memory? – Chris S Jul 1 '11 at 12:31
You should ask the person who built that bogus assumption into the question, Chris S. You've continued with another implicit bogus assumption as well, by the way. Hint: Ask yourself: What is the actual cause of such behaviour of uninitialized automatic variables in programs (this is better suited to StackOverflow, really) when one observes it? Another hint: We don't in fact really need to know what the operating system is. – JdeBP Jul 1 '11 at 12:38
show 2 more comments

closed as off topic by Chopper3 Jul 1 '11 at 12:45

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

I'm sure some OSes do clear memory before assigning to an application, and there are secure memory functions where the OS will wipe the memory after it's freed in some OSes, but most do not. In any case you should never assume memory will be cleared.

share|improve this answer
I suppose my Windows programming knowledge is a bit antiquated. – Chris S Jul 1 '11 at 12:38
So... what is the answer for NT based OSes? – ytoledano Jul 1 '11 at 12:47
Is this the standard mem alloc function used by Windows programmers or is it just something that exists but is rarely used? – SvW Jul 1 '11 at 12:49
3  
@ytoledano, the answer is that it should never matter because using an unitialized variable for anything is just begging for your program to go off into the grass. – Chris S Jul 1 '11 at 12:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.