Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've noticed that when you open a program, close it, then open it again, it seems to open a lot quicker the second time around.

Is this because the second time it's already in RAM?

Put another way, I assume once a program closes, it's memory space gets marked as unused. If that program is opened again before it's old memory space gets used, does it have to reload the program in its entirety from disk?

share|improve this question
1  
This is the difference between free and inactive memory. Both are sail able as needed, but the latter already contains data that can be reused. –  Daniel Beck Jan 28 '12 at 4:47
1  
You're going to get vague and woolly answers because you've asked a vague and woolly question. The answer to this question is operating-system-dependent, but you haven't specified an operating system. The behaviour on an old Unix with "sticky text" programs is different to the behaviour on Windows NT, which is different to the behaviour on Linux, which is different to the behaviours on BSDs and MacOS, which is different to the behaviour on Solaris — because their caching and memory management architectures are all subtly, or even grossly, different from one another. –  JdeBP Jan 28 '12 at 11:39
    
@JdeBP Fair point. I guess I was looking for the OS 101 answer, or at least some ideas that I hadn't considered, like the disk caching mentioned below. –  Dean Jan 28 '12 at 19:22

2 Answers 2

up vote 1 down vote accepted

In general, when an application closes/ends the storage it occupied is instantly released, and if you restart the application it will be loaded from disk afresh, into "new" storage.

The biggest exception to this would be on some "smart phones", where sometimes when you "end" an application it's not really ended immediately but is simply "backgrounded" for a period of time on the assumption that you may restart it in the near future. But if you don't use the application for a period of time it's eventually ended by the OS and the storage reclaimed. (So far as I know this scheme is not used on regular Microsoft or Apple computers, only phones.)

Another exception, a bit more technical, is that even though the program is ended and its storage released, the disk image of the program (or at least parts of it) may still exist in disk "cache", and may be more easily accessed a second time than the first time. This may be the cause for what you perceive as a more rapid startup the second time.

There is another, simpler reason for that faster startup, though. When you end an application and then immediately restart it there is this convenient "hole" in storage that exactly fits your program. If you start it later, after running other things, the OS has to muck around finding available storage, and this often means that it must "page out" other data in RAM, a time-consuming process.

share|improve this answer
3  
"In general, when an application closes/ends the storage it occupied is instantly released, and if you restart the application it will be loaded from disk afresh, into "new" storage." This is untrue for any modern system that uses memory mapping to lazily load binaries. –  billc.cn Jan 28 '12 at 5:17
    
That would be basically the "caching" of the disk data. But note that the actual loading of the program text is a small part of preparing a program for execution. Linking it to the RTE and preparing the data areas is the bigger part. –  Daniel R Hicks Jan 28 '12 at 12:50
    
(But you're right -- I had forgotten about that specific feature.) –  Daniel R Hicks Jan 28 '12 at 13:00
    
@DanH What you're saying is completely false for any modern operating system. And it's obviously a dumb way to do things. When a program loads, you would have two copies of the program, one running and one sitting in the disk cache -- a completely pointless waste of memory. On modern operating systems, there is no separate disk cache, most of physical memory is a page cache. –  David Schwartz Jan 28 '12 at 22:32
    
Just for grins, I opened Firefox, without doing anything other than letting it go to its home page (Google). firefox.exe is 925K, but it's virtual size is 269,000K, and it's working set is 84,000K. So the actual program text is a very small part of the overall storage requirement. Similarly for Solataire: exe -- 859K, virtual size 183,000K, working set 47,000K. –  Daniel R Hicks Jan 29 '12 at 3:17

It's no more used or unused when the program is open than when the program is closed. Memory is used if it contains useful information. It contains useful information both while the program is running and when the program is no longer running.

In fact, most operating systems don't even consider whether the program is running at all. Why keep something in memory if it's not being accessed just because a program is running? And why discard something from memory just because no program running at that instant is using it?

Operating systems go by access to data. Of course, memory that holds data that can never be accessed is considered free.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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