Both are partly true.
The pagefile is used to store infrequently accessed data, thus leaving more RAM for more important uses. This is an ongoing process and the system does not wait until RAM is full before beginning. The time required for copying data to disk is essentially free as other activities can take place while this is happening. Note that this is for infrequently accessed data only. If data is frequently accessed it will probably never be copied to the pagefile. Also note that the data is copied to the pagefile and the data remains in RAM. In the event that the RAM is needed for important purposes it can be immediately reused as the data is safely stored in the pagefile. If the data thus displaced from RAM is later needed it will be loaded from the pagefile.
The pagefile isn't normally used to store program code. There is no need to do this as there is already a perfectly good copy available in the original files they were loaded from.
The guiding principle behind all of this is too keep frequently accessed data and code in RAM, with the remainder in the pagefile or executable files files. The memory manager also strives for full memory utilization all the time. Free memory is wasted memory.
The pagefile is used to store infrequently accessed data, thus leaving more RAM for more important uses. This is an ongoing process and the system does not wait until RAM is full before beginning. The time required for copying data to disk is essentially free as other activities can take place while this is happening. Note that this is for infrequently accessed data only. If data is frequently accessed it will probably never be copied to the pagefile. Also note that the data is copied to the pagefile and the data remains in RAM. In the event that the RAM is needed for important purposes it can be immediately reused as the data is safely stored in the pagefile. If the data thus displaced from RAM is later needed it will be loaded from the pagefile.
The pagefile isn't normally used to store program code. There is no need to do this as there is already a perfectly good copy available in the original files they were loaded from.
The guiding principle behind all of this is too keep frequently accessed data and code in RAM, with the remainder in the pagefile or executable files files. The memory manager also strives for full memory utilization all the time. Free memory is wasted memory.